db9ab1d094c34822c132bc8dcd678012943cfa4f
[platform/upstream/edje.git] / src / lib / edje_calc.c
1 #include "edje_private.h"
2
3 static void                          _edje_part_make_rtl(Edje_Part_Description_Common *desc);
4 static Edje_Part_Description_Common *_edje_get_description_by_orientation(Edje *ed, Edje_Part_Description_Common *src, Edje_Part_Description_Common **dst, unsigned char type);
5
6 static void                          _edje_part_recalc_single(Edje *ed, Edje_Real_Part *ep,
7                                                               Edje_Part_Description_Common *desc, Edje_Part_Description_Common *chosen_desc,
8                                                               Edje_Real_Part *center, Edje_Real_Part *light, Edje_Real_Part *persp,
9                                                               Edje_Real_Part *rel1_to_x, Edje_Real_Part *rel1_to_y,
10                                                               Edje_Real_Part *rel2_to_x, Edje_Real_Part *rel2_to_y,
11                                                               Edje_Real_Part *confine_to, Edje_Calc_Params *params,
12                                                               FLOAT_T pos);
13
14 void
15 _edje_part_pos_set(Edje *ed, Edje_Real_Part *ep, int mode, FLOAT_T pos, FLOAT_T v1, FLOAT_T v2)
16 {
17    FLOAT_T fp_pos;
18    FLOAT_T npos;
19
20    pos = CLAMP(pos, ZERO, FROM_INT(1));
21
22    fp_pos = pos;
23
24    npos = ZERO;
25 #if 0 // old code - easy to enable for comparing float vs fixed point
26       /* take linear pos along timescale and use interpolation method */
27    switch (mode)
28      {
29       case EDJE_TWEEN_MODE_SINUSOIDAL:
30         /* npos = (1.0 - cos(pos * PI)) / 2.0; */
31         npos = DIV2(SUB(FROM_INT(1),
32                         COS(MUL(fp_pos,
33                                 PI))));
34         break;
35
36       case EDJE_TWEEN_MODE_ACCELERATE:
37         /* npos = 1.0 - sin((PI / 2.0) + (pos * PI / 2.0)); */
38         npos = SUB(FROM_INT(1),
39                    SIN(ADD(DIV2(PI),
40                            MUL(fp_pos,
41                                DIV2(PI)))));
42         break;
43
44       case EDJE_TWEEN_MODE_DECELERATE:
45         /* npos = sin(pos * PI / 2.0); */
46         npos = SIN(MUL(fp_pos,
47                        DIV2(PI)));
48         break;
49
50       case EDJE_TWEEN_MODE_LINEAR:
51         npos = fp_pos;
52         break;
53
54       default:
55         npos = fp_pos;
56         break;
57      }
58 #else
59    switch (mode & EDJE_TWEEN_MODE_MASK)
60      {
61       case EDJE_TWEEN_MODE_SINUSOIDAL:
62         npos = FROM_DOUBLE(ecore_animator_pos_map(TO_DOUBLE(pos),
63                                                   ECORE_POS_MAP_SINUSOIDAL,
64                                                   0.0, 0.0));
65         break;
66
67       case EDJE_TWEEN_MODE_ACCELERATE:
68         npos = FROM_DOUBLE(ecore_animator_pos_map(TO_DOUBLE(pos),
69                                                   ECORE_POS_MAP_ACCELERATE,
70                                                   0.0, 0.0));
71         break;
72
73       case EDJE_TWEEN_MODE_DECELERATE:
74         npos = FROM_DOUBLE(ecore_animator_pos_map(TO_DOUBLE(pos),
75                                                   ECORE_POS_MAP_DECELERATE,
76                                                   0.0, 0.0));
77         break;
78
79       case EDJE_TWEEN_MODE_LINEAR:
80         npos = fp_pos;
81 /*        npos = FROM_DOUBLE(ecore_animator_pos_map(TO_DOUBLE(pos),
82                                                   ECORE_POS_MAP_LINEAR,
83                                                   0.0, 0.0));
84  */
85         break;
86
87       case EDJE_TWEEN_MODE_ACCELERATE_FACTOR:
88         npos = FROM_DOUBLE(ecore_animator_pos_map(TO_DOUBLE(pos),
89                                                   ECORE_POS_MAP_ACCELERATE_FACTOR,
90                                                   TO_DOUBLE(v1), 0.0));
91         break;
92
93       case EDJE_TWEEN_MODE_DECELERATE_FACTOR:
94         npos = FROM_DOUBLE(ecore_animator_pos_map(TO_DOUBLE(pos),
95                                                   ECORE_POS_MAP_DECELERATE_FACTOR,
96                                                   TO_DOUBLE(v1), 0.0));
97         break;
98
99       case EDJE_TWEEN_MODE_SINUSOIDAL_FACTOR:
100         npos = FROM_DOUBLE(ecore_animator_pos_map(TO_DOUBLE(pos),
101                                                   ECORE_POS_MAP_SINUSOIDAL_FACTOR,
102                                                   TO_DOUBLE(v1), 0.0));
103         break;
104
105       case EDJE_TWEEN_MODE_DIVISOR_INTERP:
106         npos = FROM_DOUBLE(ecore_animator_pos_map(TO_DOUBLE(pos),
107                                                   ECORE_POS_MAP_DIVISOR_INTERP,
108                                                   TO_DOUBLE(v1), TO_DOUBLE(v2)));
109         break;
110
111       case EDJE_TWEEN_MODE_BOUNCE:
112         npos = FROM_DOUBLE(ecore_animator_pos_map(TO_DOUBLE(pos),
113                                                   ECORE_POS_MAP_BOUNCE,
114                                                   TO_DOUBLE(v1), TO_DOUBLE(v2)));
115         break;
116
117       case EDJE_TWEEN_MODE_SPRING:
118         npos = FROM_DOUBLE(ecore_animator_pos_map(TO_DOUBLE(pos),
119                                                   ECORE_POS_MAP_SPRING,
120                                                   TO_DOUBLE(v1), TO_DOUBLE(v2)));
121         break;
122
123       default:
124         npos = fp_pos;
125         break;
126      }
127 #endif
128    if (npos == ep->description_pos) return;
129
130    ep->description_pos = npos;
131
132    ed->dirty = 1;
133    ed->recalc_call = 1;
134 #ifdef EDJE_CALC_CACHE
135    ep->invalidate = 1;
136 #endif
137 }
138
139 /**
140  * Returns part description
141  *
142  * @internal
143  *
144  * Converts part description to RTL-desc.
145  *
146  * @param desc Pointer to desc buffer.
147  *
148  **/
149 static void
150 _edje_part_make_rtl(Edje_Part_Description_Common *desc)
151 {
152    double t;
153    int i;
154
155    if (!desc)
156      return;
157
158    /* This makes alignment right-oriented */
159    desc->align.x = 1.0 - desc->align.x;
160
161    /* same as above for relative components */
162    t = desc->rel1.relative_x;
163    desc->rel1.relative_x = 1.0 - desc->rel2.relative_x;
164    desc->rel2.relative_x = 1.0 - t;
165
166    /* +1 and +1 are because how edje works with right
167     * side borders - nothing is printed beyond that limit
168     *
169     * rel2 is now to the left of rel1, and Edje assumes
170     * the opposite so we switch corners on x-axis to define
171     * offset from right to left */
172    i = desc->rel1.offset_x;
173    desc->rel1.offset_x = -(desc->rel2.offset_x + 1);
174    desc->rel2.offset_x = -(i + 1);
175
176    i = desc->rel1.id_x;
177    desc->rel1.id_x = desc->rel2.id_x;
178    desc->rel2.id_x = i;
179 }
180
181 /**
182  * Returns part description
183  *
184  * @internal
185  *
186  * Returns part description according to object orientation.
187  * When object is in RTL-orientation (RTL flag is set)
188  * this returns the RTL-desc of it.
189  * RTL-desc would be allocated if was not created by a previous call.
190  * The dst pointer is updated in case of an allocation.
191  *
192  * @param ed Edje object.
193  * @param src The Left To Right (LTR), original desc.
194  * @param dst Pointer to Right To Left (RTL) desc-list.
195  * @param type name of dec type. Example: "default".
196  *
197  * @return Edje part description.
198  *
199  **/
200 static Edje_Part_Description_Common *
201 _edje_get_description_by_orientation(Edje *ed, Edje_Part_Description_Common *src, Edje_Part_Description_Common **dst, unsigned char type)
202 {
203    Edje_Part_Description_Common *desc_rtl = NULL;
204    Edje_Part_Collection_Directory_Entry *ce;
205    size_t memsize = 0;
206
207    /* RTL flag is not set, return original description */
208    if (!edje_object_mirrored_get(ed->obj))
209      return src;
210
211    if (*dst)
212      return *dst;  /* Was allocated before and we should use it */
213
214 #define EDIT_ALLOC_POOL_RTL(Short, Type, Name)                        \
215 case EDJE_PART_TYPE_##Short:                                          \
216 {                                                                     \
217    Edje_Part_Description_##Type * Name;                               \
218    Name = eina_mempool_malloc(ce->mp_rtl.Short,                       \
219                               sizeof (Edje_Part_Description_##Type)); \
220    memset(Name, 0, sizeof(Edje_Part_Description_##Type));             \
221    desc_rtl = &Name->common;                                          \
222    memsize = sizeof(Edje_Part_Description_##Type);                    \
223    break;                                                             \
224 }
225
226    ce = eina_hash_find(ed->file->collection, ed->group);
227
228    switch (type)
229      {
230       case EDJE_PART_TYPE_RECTANGLE:
231         desc_rtl = eina_mempool_malloc(ce->mp_rtl.RECTANGLE,
232                                        sizeof (Edje_Part_Description_Common));
233         ce->count.RECTANGLE++;
234         memsize = sizeof(Edje_Part_Description_Common);
235         break;
236
237       case EDJE_PART_TYPE_SWALLOW:
238         desc_rtl = eina_mempool_malloc(ce->mp_rtl.SWALLOW,
239                                        sizeof (Edje_Part_Description_Common));
240         ce->count.SWALLOW++;
241         memsize = sizeof(Edje_Part_Description_Common);
242         break;
243
244       case EDJE_PART_TYPE_GROUP:
245         desc_rtl = eina_mempool_malloc(ce->mp_rtl.GROUP,
246                                        sizeof (Edje_Part_Description_Common));
247         ce->count.GROUP++;
248         memsize = sizeof(Edje_Part_Description_Common);
249         break;
250
251       case EDJE_PART_TYPE_SPACER:
252         desc_rtl = eina_mempool_malloc(ce->mp_rtl.SPACER,
253                                        sizeof (Edje_Part_Description_Common));
254         ce->count.SPACER++;
255         memsize = sizeof(Edje_Part_Description_Common);
256         break;
257         EDIT_ALLOC_POOL_RTL(TEXT, Text, text);
258         EDIT_ALLOC_POOL_RTL(TEXTBLOCK, Text, text);
259         EDIT_ALLOC_POOL_RTL(IMAGE, Image, image);
260         EDIT_ALLOC_POOL_RTL(PROXY, Proxy, proxy);
261         EDIT_ALLOC_POOL_RTL(BOX, Box, box);
262         EDIT_ALLOC_POOL_RTL(TABLE, Table, table);
263         EDIT_ALLOC_POOL_RTL(EXTERNAL, External, external_params);
264      }
265
266    if (desc_rtl)
267      memcpy(desc_rtl, src, memsize);
268
269    _edje_part_make_rtl(desc_rtl);
270
271    *dst = desc_rtl;
272    return desc_rtl;
273 }
274
275 Edje_Part_Description_Common *
276 _edje_part_description_find(Edje *ed, Edje_Real_Part *rp, const char *name,
277                             double val)
278 {
279    Edje_Part *ep = rp->part;
280    Edje_Part_Description_Common *ret = NULL;
281    Edje_Part_Description_Common *d;
282
283    double min_dst = 99999.0;
284    unsigned int i;
285
286    /* RTL flag is set, return RTL description */
287    if (edje_object_mirrored_get(ed->obj))
288      if (!ep->other.desc_rtl)
289        ep->other.desc_rtl = (Edje_Part_Description_Common **)
290          calloc(ep->other.desc_count,
291                 sizeof (Edje_Part_Description_Common *));
292
293    if (!strcmp(name, "default") && val == 0.0)
294      return _edje_get_description_by_orientation(ed,
295                                                  ep->default_desc, &ep->default_desc_rtl, ep->type);
296
297    if (!strcmp(name, "custom"))
298      return rp->custom ?
299             _edje_get_description_by_orientation(ed, rp->custom->description,
300                                                  &rp->custom->description_rtl, ep->type) : NULL;
301
302    if (!strcmp(name, "default"))
303      {
304         ret = _edje_get_description_by_orientation(ed, ep->default_desc,
305                                                    &ep->default_desc_rtl,
306                                                    ep->type);
307
308         min_dst = ABS(ep->default_desc->state.value - val);
309      }
310
311    for (i = 0; i < ep->other.desc_count; ++i)
312      {
313         d = ep->other.desc[i];
314
315         if (d->state.name && (d->state.name == name ||
316                               !strcmp(d->state.name, name)))
317           {
318              double dst;
319
320              dst = ABS(d->state.value - val);
321              if (dst < min_dst)
322                {
323                   ret = _edje_get_description_by_orientation(ed, d,
324                                                              &ep->other.desc_rtl[i], ep->type);
325                   min_dst = dst;
326                }
327           }
328      }
329
330    return ret;
331 }
332
333 static int
334 _edje_image_find(Evas_Object *obj, Edje *ed, Edje_Real_Part_Set **eps, Edje_Part_Description_Image *st, Edje_Part_Image_Id *imid)
335 {
336    Edje_Image_Directory_Set_Entry *entry;
337    Edje_Image_Directory_Set *set = NULL;
338    Eina_List *l;
339    int w = 0;
340    int h = 0;
341    int id;
342
343    if (!st && !imid)
344      return -1;
345
346    if (st && !st->image.set)
347      return st->image.id;
348
349    if (imid && !imid->set)
350      return imid->id;
351
352    if (imid)
353      id = imid->id;
354    else
355      id = st->image.id;
356
357    evas_object_geometry_get(obj, NULL, NULL, &w, &h);
358
359    if (eps && *eps)
360      {
361         if ((*eps)->id == id)
362           set = (*eps)->set;
363
364         if (set)
365           if ((*eps)->entry->size.min.w <= w && w <= (*eps)->entry->size.max.w)
366             if ((*eps)->entry->size.min.h <= h && h <= (*eps)->entry->size.max.h)
367               return (*eps)->entry->id;
368      }
369
370    if (!set)
371      set = ed->file->image_dir->sets + id;
372
373    EINA_LIST_FOREACH(set->entries, l, entry)
374      {
375         if (entry->size.min.w <= w && w <= entry->size.max.w)
376           if (entry->size.min.h <= h && h <= entry->size.max.h)
377             {
378                if (eps)
379                  {
380                     if (!*eps)
381                       *eps = calloc(1, sizeof (Edje_Real_Part_Set));
382
383                     if (*eps)
384                       {
385                          (*eps)->entry = entry;
386                          (*eps)->set = set;
387                          (*eps)->id = id;
388                       }
389                  }
390                return entry->id;
391             }
392      }
393
394    return -1;
395 }
396
397 static void
398 _edje_real_part_image_set(Edje *ed, Edje_Real_Part *ep, FLOAT_T pos)
399 {
400    int image_id;
401    int image_count, image_num;
402
403    image_id = _edje_image_find(ep->object, ed,
404                                &ep->param1.set,
405                                (Edje_Part_Description_Image *)ep->param1.description,
406                                NULL);
407    if (image_id < 0)
408      {
409         Edje_Image_Directory_Entry *ie;
410
411         if (!ed->file->image_dir) ie = NULL;
412         else ie = ed->file->image_dir->entries + (-image_id) - 1;
413         if ((ie) &&
414             (ie->source_type == EDJE_IMAGE_SOURCE_TYPE_EXTERNAL) &&
415             (ie->entry))
416           {
417              evas_object_image_file_set(ep->object, ie->entry, NULL);
418           }
419      }
420    else
421      {
422         image_count = 2;
423         if (ep->param2)
424           image_count += ((Edje_Part_Description_Image *)ep->param2->description)->image.tweens_count;
425         image_num = TO_INT(MUL(pos, SUB(FROM_INT(image_count),
426                                         FROM_DOUBLE(0.5))));
427         if (image_num > (image_count - 1))
428           image_num = image_count - 1;
429         if (image_num <= 0)
430           {
431              image_id = _edje_image_find(ep->object, ed,
432                                          &ep->param1.set,
433                                          (Edje_Part_Description_Image *)ep->param1.description,
434                                          NULL);
435           }
436         else
437         if (ep->param2)
438           {
439              if (image_num == (image_count - 1))
440                {
441                   image_id = _edje_image_find(ep->object, ed,
442                                               &ep->param2->set,
443                                               (Edje_Part_Description_Image *)ep->param2->description,
444                                               NULL);
445                }
446              else
447                {
448                   Edje_Part_Image_Id *imid;
449
450                   imid = ((Edje_Part_Description_Image *)ep->param2->description)->image.tweens[image_num - 1];
451                   image_id = _edje_image_find(ep->object, ed, NULL, NULL, imid);
452                }
453           }
454         if (image_id < 0)
455           {
456              ERR("¨Part \"%s\" description, "
457                  "\"%s\" %3.3f with image %i index has a missing image id in a set of %i !!!",
458                  ep->part->name,
459                  ep->param1.description->state.name,
460                  ep->param1.description->state.value,
461                  image_num,
462                  image_count);
463           }
464         else
465           {
466              char buf[1024];
467
468              /* Replace snprint("edje/images/%i") == memcpy + itoa */
469 #define IMAGES "edje/images/"
470              memcpy(buf, IMAGES, strlen(IMAGES));
471              eina_convert_itoa(image_id, buf + strlen(IMAGES)); /* No need to check length as 2³² need only 10 characteres. */
472
473              evas_object_image_file_set(ep->object, ed->file->path, buf);
474              if (evas_object_image_load_error_get(ep->object) != EVAS_LOAD_ERROR_NONE)
475                {
476                   ERR("Error loading image collection \"%s\" from "
477                       "file \"%s\". Missing EET Evas loader module?",
478                       buf, ed->file->path);
479                   switch (evas_object_image_load_error_get(ep->object))
480                     {
481                      case EVAS_LOAD_ERROR_GENERIC:
482                        ERR("Error type: EVAS_LOAD_ERROR_GENERIC");
483                        break;
484
485                      case EVAS_LOAD_ERROR_DOES_NOT_EXIST:
486                        ERR("Error type: EVAS_LOAD_ERROR_DOES_NOT_EXIST");
487                        break;
488
489                      case EVAS_LOAD_ERROR_PERMISSION_DENIED:
490                        ERR("Error type: EVAS_LOAD_ERROR_PERMISSION_DENIED");
491                        break;
492
493                      case EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED:
494                        ERR("Error type: EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED");
495                        break;
496
497                      case EVAS_LOAD_ERROR_CORRUPT_FILE:
498                        ERR("Error type: EVAS_LOAD_ERROR_CORRUPT_FILE");
499                        break;
500
501                      case EVAS_LOAD_ERROR_UNKNOWN_FORMAT:
502                        ERR("Error type: EVAS_LOAD_ERROR_UNKNOWN_FORMAT");
503                        break;
504
505                      default:
506                        ERR("Error type: ???");
507                        break;
508                     }
509                }
510           }
511      }
512 }
513
514 static void
515 _edje_real_part_rel_to_apply(Edje *ed, Edje_Real_Part *ep, Edje_Real_Part_State *state)
516 {
517    state->rel1_to_x = state->rel1_to_y = NULL;
518    state->rel2_to_x = state->rel2_to_y = NULL;
519
520    if (state->description)
521      {
522         if (state->description->rel1.id_x >= 0)
523           state->rel1_to_x = ed->table_parts[state->description->rel1.id_x % ed->table_parts_size];
524         if (state->description->rel1.id_y >= 0)
525           state->rel1_to_y = ed->table_parts[state->description->rel1.id_y % ed->table_parts_size];
526         if (state->description->rel2.id_x >= 0)
527           state->rel2_to_x = ed->table_parts[state->description->rel2.id_x % ed->table_parts_size];
528         if (state->description->rel2.id_y >= 0)
529           state->rel2_to_y = ed->table_parts[state->description->rel2.id_y % ed->table_parts_size];
530
531         if (ep->part->type == EDJE_PART_TYPE_EXTERNAL)
532           {
533              Edje_Part_Description_External *external;
534
535              external = (Edje_Part_Description_External *)state->description;
536
537              if (state->external_params)
538                _edje_external_parsed_params_free(ep->swallowed_object, state->external_params);
539              state->external_params = _edje_external_params_parse(ep->swallowed_object, external->external_params);
540           }
541      }
542 }
543
544 void
545 _edje_part_description_apply(Edje *ed, Edje_Real_Part *ep, const char *d1, double v1, const char *d2, double v2)
546 {
547    Edje_Part_Description_Common *epd1;
548    Edje_Part_Description_Common *epd2 = NULL;
549    Edje_Part_Description_Common *chosen_desc;
550
551    Edje_Part_Description_Image *epdi;
552
553    if (!d1) d1 = "default";
554
555    epd1 = _edje_part_description_find(ed, ep, d1, v1);
556    if (!epd1)
557      epd1 = ep->part->default_desc;  /* never NULL */
558
559    if (d2)
560      epd2 = _edje_part_description_find(ed, ep, d2, v2);
561
562    epdi = (Edje_Part_Description_Image *)epd2;
563
564    /* There is an animation if both description are different or if description is an image with tweens */
565    if (epd2 && (epd1 != epd2 || (ep->part->type == EDJE_PART_TYPE_IMAGE && epdi->image.tweens_count)))
566      {
567         if (!ep->param2)
568           {
569              ep->param2 = eina_mempool_malloc(_edje_real_part_state_mp,
570                                               sizeof(Edje_Real_Part_State));
571              memset(ep->param2, 0, sizeof(Edje_Real_Part_State));
572           }
573         else if (ep->part->type == EDJE_PART_TYPE_EXTERNAL)
574           _edje_external_parsed_params_free(ep->swallowed_object,
575                                             ep->param2->external_params);
576         ep->param2->external_params = NULL;
577      }
578    else
579    if (ep->param2)
580      {
581         if (ep->part->type == EDJE_PART_TYPE_EXTERNAL)
582           _edje_external_parsed_params_free(ep->swallowed_object,
583                                             ep->param2->external_params);
584         if (ep->param2)
585           free(ep->param2->set);
586         eina_mempool_free(_edje_real_part_state_mp, ep->param2);
587         ep->param2 = NULL;
588      }
589
590    chosen_desc = ep->chosen_description;
591    ep->param1.description = epd1;
592    ep->chosen_description = epd1;
593
594    _edje_real_part_rel_to_apply(ed, ep, &ep->param1);
595
596    if (ep->param2)
597      {
598         ep->param2->description = epd2;
599
600         _edje_real_part_rel_to_apply(ed, ep, ep->param2);
601
602         if (ep->description_pos > FROM_DOUBLE(0.0))
603           ep->chosen_description = epd2;
604      }
605
606    if (chosen_desc != ep->chosen_description &&
607        ep->part->type == EDJE_PART_TYPE_EXTERNAL)
608      _edje_external_recalc_apply(ed, ep, NULL, chosen_desc);
609
610    ed->recalc_hints = 1;
611    ed->dirty = 1;
612    ed->recalc_call = 1;
613 #ifdef EDJE_CALC_CACHE
614    ep->invalidate = 1;
615 #endif
616 }
617
618 void
619 _edje_recalc(Edje *ed)
620 {
621    if ((ed->freeze > 0) || (_edje_freeze_val > 0))
622      {
623         ed->recalc = 1;
624         if (!ed->calc_only)
625           {
626              if (_edje_freeze_val > 0)
627                {
628                   if (!ed->freeze_calc)
629                     {
630                        _edje_freeze_calc_count++;
631                        _edje_freeze_calc_list = eina_list_append(_edje_freeze_calc_list, ed);
632                        ed->freeze_calc = 1;
633                     }
634                }
635              return;
636           }
637      }
638 // XXX: dont need this with current smart calc infra. remove me later
639 //   if (ed->postponed) return;
640 //   if (!ed->calc_only)
641    evas_object_smart_changed(ed->obj);
642 // XXX: dont need this with current smart calc infra. remove me later
643 //   ed->postponed = 1;
644 }
645
646 void
647 _edje_recalc_do(Edje *ed)
648 {
649    unsigned int i;
650    Eina_Bool need_calc;
651
652 // XXX: dont need this with current smart calc infra. remove me later
653 //   ed->postponed = 0;
654    need_calc = evas_object_smart_need_recalculate_get(ed->obj);
655    evas_object_smart_need_recalculate_set(ed->obj, 0);
656    if (!ed->dirty) return;
657    ed->have_mapped_part = 0;
658    ed->dirty = 0;
659    ed->state++;
660    for (i = 0; i < ed->table_parts_size; i++)
661      {
662         Edje_Real_Part *ep;
663
664         ep = ed->table_parts[i];
665         ep->calculated = FLAG_NONE;
666         ep->calculating = FLAG_NONE;
667      }
668    for (i = 0; i < ed->table_parts_size; i++)
669      {
670         Edje_Real_Part *ep;
671
672         ep = ed->table_parts[i];
673         if (ep->calculated != FLAG_XY)
674           _edje_part_recalc(ed, ep, (~ep->calculated) & FLAG_XY, NULL);
675      }
676    if (!ed->calc_only) ed->recalc = 0;
677 #ifdef EDJE_CALC_CACHE
678    ed->all_part_change = 0;
679    ed->text_part_change = 0;
680 #endif
681    if (!ed->calc_only)
682      {
683         if (ed->recalc_call)
684           evas_object_smart_callback_call(ed->obj, "recalc", NULL);
685      }
686    else
687      evas_object_smart_need_recalculate_set(ed->obj, need_calc);
688    ed->recalc_call = 0;
689
690    if (ed->update_hints && ed->recalc_hints && !ed->calc_only)
691      {
692         Evas_Coord w, h;
693
694         ed->recalc_hints = 0;
695
696         edje_object_size_min_calc(ed->obj, &w, &h);
697         evas_object_size_hint_min_set(ed->obj, w, h);
698      }
699
700    if (!ed->collection) return;
701
702    for (i = 0; i < ed->collection->limits.parts_count; i++)
703      {
704         const char *name;
705         unsigned char limit;
706         int part;
707
708         part = ed->collection->limits.parts[i].part;
709         name = ed->collection->parts[part]->name;
710         limit = ed->table_parts[part]->chosen_description->limit;
711         switch (limit)
712           {
713            case 0:
714              ed->collection->limits.parts[i].width = EDJE_PART_LIMIT_UNKNOWN;
715              ed->collection->limits.parts[i].height = EDJE_PART_LIMIT_UNKNOWN;
716              break;
717
718            case 1:
719              ed->collection->limits.parts[i].height = EDJE_PART_LIMIT_UNKNOWN;
720              break;
721
722            case 2:
723              ed->collection->limits.parts[i].width = EDJE_PART_LIMIT_UNKNOWN;
724              break;
725
726            case 3:
727              break;
728           }
729
730         if ((limit & 1) == 1)
731           {
732              if (ed->table_parts[part]->w > 0 &&
733                  (ed->collection->limits.parts[i].width != EDJE_PART_LIMIT_OVER))
734                {
735                   ed->collection->limits.parts[i].width = EDJE_PART_LIMIT_OVER;
736                   _edje_emit(ed, "limit,width,over", name);
737                }
738              else if (ed->table_parts[part]->w < 0 &&
739                       ed->collection->limits.parts[i].width != EDJE_PART_LIMIT_BELOW)
740                {
741                   ed->collection->limits.parts[i].width = EDJE_PART_LIMIT_BELOW;
742                   _edje_emit(ed, "limit,width,below", name);
743                }
744              else if (ed->table_parts[part]->w == 0 &&
745                       ed->collection->limits.parts[i].width != EDJE_PART_LIMIT_ZERO)
746                {
747                   ed->collection->limits.parts[i].width = EDJE_PART_LIMIT_ZERO;
748                   _edje_emit(ed, "limit,width,zero", name);
749                }
750           }
751         if ((limit & 2) == 2)
752           {
753              if (ed->table_parts[part]->h > 0 &&
754                  (ed->collection->limits.parts[i].height != EDJE_PART_LIMIT_OVER))
755                {
756                   ed->collection->limits.parts[i].height = EDJE_PART_LIMIT_OVER;
757                   _edje_emit(ed, "limit,height,over", name);
758                }
759              else if (ed->table_parts[part]->h < 0 &&
760                       ed->collection->limits.parts[i].height != EDJE_PART_LIMIT_BELOW)
761                {
762                   ed->collection->limits.parts[i].height = EDJE_PART_LIMIT_BELOW;
763                   _edje_emit(ed, "limit,height,below", name);
764                }
765              else if (ed->table_parts[part]->h == 0 &&
766                       ed->collection->limits.parts[i].height != EDJE_PART_LIMIT_ZERO)
767                {
768                   ed->collection->limits.parts[i].height = EDJE_PART_LIMIT_ZERO;
769                   _edje_emit(ed, "limit,height,zero", name);
770                }
771           }
772      }
773 }
774
775 void
776 _edje_part_recalc_1(Edje *ed, Edje_Real_Part *ep)
777 {
778    _edje_part_recalc(ed, ep, FLAG_XY, NULL);
779 }
780
781 int
782 _edje_part_dragable_calc(Edje *ed __UNUSED__, Edje_Real_Part *ep, FLOAT_T *x, FLOAT_T *y)
783 {
784    if (ep->drag)
785      {
786         if (ep->drag->confine_to)
787           {
788              FLOAT_T dx, dy, dw, dh;
789              int ret = 0;
790
791              if ((ep->part->dragable.x != 0) &&
792                  (ep->part->dragable.y != 0)) ret = 3;
793              else if (ep->part->dragable.x != 0)
794                ret = 1;
795              else if (ep->part->dragable.y != 0)
796                ret = 2;
797
798              dx = FROM_INT(ep->x - ep->drag->confine_to->x);
799              dw = FROM_INT(ep->drag->confine_to->w - ep->w);
800              if (dw != ZERO) dx = DIV(dx, dw);
801              else dx = ZERO;
802
803              dy = FROM_INT(ep->y - ep->drag->confine_to->y);
804              dh = FROM_INT(ep->drag->confine_to->h - ep->h);
805              if (dh != ZERO) dy = DIV(dy, dh);
806              else dy = ZERO;
807
808              if (x) *x = dx;
809              if (y) *y = dy;
810
811              return ret;
812           }
813         else
814           {
815              if (x) *x = ADD(FROM_INT(ep->drag->tmp.x), ep->drag->x);
816              if (y) *y = ADD(FROM_INT(ep->drag->tmp.y), ep->drag->y);
817              return 0;
818           }
819      }
820    if (x) *x = ZERO;
821    if (y) *y = ZERO;
822    return 0;
823 }
824
825 void
826 _edje_dragable_pos_set(Edje *ed, Edje_Real_Part *ep, FLOAT_T x, FLOAT_T y)
827 {
828    /* check whether this part is dragable at all */
829    if (!ep->drag) return;
830
831    /* instead of checking for equality, we really should check that
832     * the difference is greater than foo, but I have no idea what
833     * value we would set foo to, because it would depend on the
834     * size of the dragable...
835     */
836    if (ep->drag->x != x || ep->drag->tmp.x)
837      {
838         ep->drag->x = x;
839         ep->drag->tmp.x = 0;
840         ep->drag->need_reset = 0;
841         ed->dirty = 1;
842         ed->recalc_call = 1;
843      }
844
845    if (ep->drag->y != y || ep->drag->tmp.y)
846      {
847         ep->drag->y = y;
848         ep->drag->tmp.y = 0;
849         ep->drag->need_reset = 0;
850         ed->dirty = 1;
851         ed->recalc_call = 1;
852      }
853
854 #ifdef EDJE_CALC_CACHE
855    ep->invalidate = 1;
856 #endif
857    _edje_recalc(ed); /* won't do anything if dirty flag isn't set */
858 }
859
860 static void
861 _edje_part_recalc_single_rel(Edje *ed,
862                              Edje_Real_Part *ep __UNUSED__,
863                              Edje_Part_Description_Common *desc,
864                              Edje_Real_Part *rel1_to_x,
865                              Edje_Real_Part *rel1_to_y,
866                              Edje_Real_Part *rel2_to_x,
867                              Edje_Real_Part *rel2_to_y,
868                              Edje_Calc_Params *params)
869 {
870    FLOAT_T x, w;
871    FLOAT_T y, h;
872
873    if (rel1_to_x)
874      x = ADD(FROM_INT(desc->rel1.offset_x + rel1_to_x->x),
875              SCALE(desc->rel1.relative_x, rel1_to_x->w));
876    else
877      x = ADD(FROM_INT(desc->rel1.offset_x),
878              SCALE(desc->rel1.relative_x, ed->w));
879    params->x = TO_INT(x);
880
881    if (rel2_to_x)
882      w = ADD(SUB(ADD(FROM_INT(desc->rel2.offset_x + rel2_to_x->x),
883                      SCALE(desc->rel2.relative_x, rel2_to_x->w)),
884                  x),
885              FROM_INT(1));
886    else
887      w = ADD(SUB(ADD(FROM_INT(desc->rel2.offset_x),
888                      SCALE(desc->rel2.relative_x, ed->w)),
889                  x),
890              FROM_INT(1));
891    params->w = TO_INT(w);
892
893    if (rel1_to_y)
894      y = ADD(FROM_INT(desc->rel1.offset_y + rel1_to_y->y),
895              SCALE(desc->rel1.relative_y, rel1_to_y->h));
896    else
897      y = ADD(FROM_INT(desc->rel1.offset_y),
898              SCALE(desc->rel1.relative_y, ed->h));
899    params->y = TO_INT(y);
900
901    if (rel2_to_y)
902      h = ADD(SUB(ADD(FROM_INT(desc->rel2.offset_y + rel2_to_y->y),
903                      SCALE(desc->rel2.relative_y, rel2_to_y->h)),
904                  y),
905              FROM_INT(1));
906    else
907      h = ADD(SUB(ADD(FROM_INT(desc->rel2.offset_y),
908                      SCALE(desc->rel2.relative_y, ed->h)),
909                  y),
910              FROM_INT(1));
911    params->h = TO_INT(h);
912 }
913
914 static Edje_Internal_Aspect
915 _edje_part_recalc_single_aspect(Edje *ed,
916                                 Edje_Real_Part *ep,
917                                 Edje_Part_Description_Common *desc,
918                                 Edje_Calc_Params *params,
919                                 int *minw, int *minh,
920                                 int *maxw, int *maxh,
921                                 FLOAT_T pos)
922 {
923    Edje_Internal_Aspect apref = EDJE_ASPECT_PREFER_NONE;
924    FLOAT_T aspect, amax, amin;
925    FLOAT_T new_w = ZERO, new_h = ZERO, want_x, want_y, want_w, want_h;
926
927    if (params->h <= ZERO) aspect = FROM_INT(999999);
928    else aspect = DIV(FROM_INT(params->w), FROM_INT(params->h));
929    amax = desc->aspect.max;
930    amin = desc->aspect.min;
931    if (desc->aspect.prefer == EDJE_ASPECT_PREFER_SOURCE &&
932        ep->part->type == EDJE_PART_TYPE_IMAGE)
933      {
934         Evas_Coord w, h;
935
936         /* We only need pose to find the right image that would be displayed,
937            and the right aspect ratio in that case */
938         _edje_real_part_image_set(ed, ep, pos);
939         evas_object_image_size_get(ep->object, &w, &h);
940         amin = amax = DIV(FROM_INT(w), FROM_INT(h));
941      }
942    if ((ep->swallow_params.aspect.w > 0) &&
943        (ep->swallow_params.aspect.h > 0))
944      amin = amax =
945          DIV(FROM_INT(ep->swallow_params.aspect.w),
946              FROM_INT(ep->swallow_params.aspect.h));
947    want_x = FROM_INT(params->x);
948    want_w = new_w = FROM_INT(params->w);
949
950    want_y = FROM_INT(params->y);
951    want_h = new_h = FROM_INT(params->h);
952
953    if ((amin > ZERO) && (amax > ZERO))
954      {
955         apref = desc->aspect.prefer;
956         if (ep->swallow_params.aspect.mode > EDJE_ASPECT_CONTROL_NONE)
957           {
958              switch (ep->swallow_params.aspect.mode)
959                {
960                 case EDJE_ASPECT_CONTROL_NEITHER:
961                   apref = EDJE_ASPECT_PREFER_NONE;
962                   break;
963
964                 case EDJE_ASPECT_CONTROL_HORIZONTAL:
965                   apref = EDJE_ASPECT_PREFER_HORIZONTAL;
966                   break;
967
968                 case EDJE_ASPECT_CONTROL_VERTICAL:
969                   apref = EDJE_ASPECT_PREFER_VERTICAL;
970                   break;
971
972                 case EDJE_ASPECT_CONTROL_BOTH:
973                   apref = EDJE_ASPECT_PREFER_BOTH;
974                   break;
975
976                 default:
977                   break;
978                }
979           }
980         switch (apref)
981           {
982            case EDJE_ASPECT_PREFER_NONE:
983              /* keep both dimensions in check */
984              /* adjust for min aspect (width / height) */
985              if ((amin > ZERO) && (aspect < amin))
986                {
987                   new_h = DIV(FROM_INT(params->w), amin);
988                   new_w = SCALE(amin, params->h);
989                }
990              /* adjust for max aspect (width / height) */
991              if ((amax > ZERO) && (aspect > amax))
992                {
993                   new_h = DIV(FROM_INT(params->w), amax);
994                   new_w = SCALE(amax, params->h);
995                }
996              if ((amax > ZERO) && (new_w < FROM_INT(params->w)))
997                {
998                   new_w = FROM_INT(params->w);
999                   new_h = DIV(FROM_INT(params->w), amax);
1000                }
1001              if ((amax > ZERO) && (new_h < FROM_INT(params->h)))
1002                {
1003                   new_w = SCALE(amax, params->h);
1004                   new_h = FROM_INT(params->h);
1005                }
1006              break;
1007
1008            /* prefer vertical size as determiner */
1009            case  EDJE_ASPECT_PREFER_VERTICAL:
1010              /* keep both dimensions in check */
1011              /* adjust for max aspect (width / height) */
1012              if ((amax > ZERO) && (aspect > amax))
1013                new_w = SCALE(amax, params->h);
1014              /* adjust for min aspect (width / height) */
1015              if ((amin > ZERO) && (aspect < amin))
1016                new_w = SCALE(amin, params->h);
1017              break;
1018
1019            /* prefer horizontal size as determiner */
1020            case EDJE_ASPECT_PREFER_HORIZONTAL:
1021              /* keep both dimensions in check */
1022              /* adjust for max aspect (width / height) */
1023              if ((amax > ZERO) && (aspect > amax))
1024                new_h = DIV(FROM_INT(params->w), amax);
1025              /* adjust for min aspect (width / height) */
1026              if ((amin > ZERO) && (aspect < amin))
1027                new_h = DIV(FROM_INT(params->w), amin);
1028              break;
1029
1030            case EDJE_ASPECT_PREFER_SOURCE:
1031            case EDJE_ASPECT_PREFER_BOTH:
1032              /* keep both dimensions in check */
1033              /* adjust for max aspect (width / height) */
1034              if ((amax > ZERO) && (aspect > amax))
1035                {
1036                   new_w = SCALE(amax, params->h);
1037                   new_h = DIV(FROM_INT(params->w), amax);
1038                }
1039              /* adjust for min aspect (width / height) */
1040              if ((amin > ZERO) && (aspect < amin))
1041                {
1042                   new_w = SCALE(amin, params->h);
1043                   new_h = DIV(FROM_INT(params->w), amin);
1044                }
1045              break;
1046
1047            default:
1048              break;
1049           }
1050
1051         if (!((amin > ZERO) && (amax > ZERO) &&
1052               (apref == EDJE_ASPECT_PREFER_NONE)))
1053           {
1054              if ((*maxw >= 0) && (new_w > FROM_INT(*maxw)))
1055                new_w = FROM_INT(*maxw);
1056              if (new_w < FROM_INT(*minw))
1057                new_w = FROM_INT(*minw);
1058
1059              if ((FROM_INT(*maxh) >= 0) && (new_h > FROM_INT(*maxh)))
1060                new_h = FROM_INT(*maxh);
1061              if (new_h < FROM_INT(*minh))
1062                new_h = FROM_INT(*minh);
1063           }
1064
1065         /* do real adjustment */
1066         if (apref == EDJE_ASPECT_PREFER_BOTH)
1067           {
1068              if (amin == ZERO) amin = amax;
1069              if (amin != ZERO)
1070                {
1071                   /* fix h and vary w */
1072                   if (new_w > FROM_INT(params->w))
1073                     {
1074                        //                 params->w = new_w;
1075                        // EXCEEDS BOUNDS in W
1076                        new_h = DIV(FROM_INT(params->w), amin);
1077                        new_w = FROM_INT(params->w);
1078                        if (new_h > FROM_INT(params->h))
1079                          {
1080                             new_h = FROM_INT(params->h);
1081                             new_w = SCALE(amin, params->h);
1082                          }
1083                     }
1084                   /* fix w and vary h */
1085                   else
1086                     {
1087                        //                 params->h = new_h;
1088                        // EXCEEDS BOUNDS in H
1089                        new_h = FROM_INT(params->h);
1090                        new_w = SCALE(amin, params->h);
1091                        if (new_w > FROM_INT(params->w))
1092                          {
1093                             new_h = DIV(FROM_INT(params->w), amin);
1094                             new_w = FROM_INT(params->w);
1095                          }
1096                     }
1097                   params->w = TO_INT(new_w);
1098                   params->h = TO_INT(new_h);
1099                }
1100           }
1101      }
1102    if (apref != EDJE_ASPECT_PREFER_BOTH)
1103      {
1104         if ((amin > 0.0) && (amax > ZERO) && (apref == EDJE_ASPECT_PREFER_NONE))
1105           {
1106              params->w = TO_INT(new_w);
1107              params->h = TO_INT(new_h);
1108           }
1109         else if ((FROM_INT(params->h) - new_h) > (FROM_INT(params->w) - new_w))
1110           {
1111              if (params->h < TO_INT(new_h))
1112                params->h = TO_INT(new_h);
1113              else if (params->h > TO_INT(new_h))
1114                params->h = TO_INT(new_h);
1115              if (apref == EDJE_ASPECT_PREFER_VERTICAL)
1116                params->w = TO_INT(new_w);
1117           }
1118         else
1119           {
1120              if (params->w < TO_INT(new_w))
1121                params->w = TO_INT(new_w);
1122              else if (params->w > TO_INT(new_w))
1123                params->w = TO_INT(new_w);
1124              if (apref == EDJE_ASPECT_PREFER_HORIZONTAL)
1125                params->h = TO_INT(new_h);
1126           }
1127      }
1128    params->x = TO_INT(ADD(want_x,
1129                           MUL(SUB(want_w, FROM_INT(params->w)),
1130                               desc->align.x)));
1131    params->y = TO_INT(ADD(want_y,
1132                           MUL(SUB(want_h, FROM_INT(params->h)),
1133                               desc->align.y)));
1134    return apref;
1135 }
1136
1137 static void
1138 _edje_part_recalc_single_step(Edje_Part_Description_Common *desc,
1139                               Edje_Calc_Params *params)
1140 {
1141    if (desc->step.x > 0)
1142      {
1143         int steps;
1144         int new_w;
1145
1146         steps = params->w / desc->step.x;
1147         new_w = desc->step.x * steps;
1148         if (params->w > new_w)
1149           {
1150              params->x += TO_INT(SCALE(desc->align.x, (params->w - new_w)));
1151              params->w = new_w;
1152           }
1153      }
1154
1155    if (desc->step.y > 0)
1156      {
1157         int steps;
1158         int new_h;
1159
1160         steps = params->h / desc->step.y;
1161         new_h = desc->step.y * steps;
1162         if (params->h > new_h)
1163           {
1164              params->y += TO_INT(SCALE(desc->align.y, (params->h - new_h)));
1165              params->h = new_h;
1166           }
1167      }
1168 }
1169
1170 static void
1171 _edje_part_recalc_single_textblock(FLOAT_T sc,
1172                                    Edje *ed,
1173                                    Edje_Real_Part *ep,
1174                                    Edje_Part_Description_Text *chosen_desc,
1175                                    Edje_Calc_Params *params,
1176                                    int *minw, int *minh,
1177                                    int *maxw, int *maxh)
1178 {
1179    if (chosen_desc)
1180      {
1181         Evas_Coord tw, th, ins_l, ins_r, ins_t, ins_b;
1182         const char *text = "";
1183         const char *style = "";
1184         Edje_Style *stl = NULL;
1185         const char *tmp;
1186         Eina_List *l;
1187
1188         if (chosen_desc->text.id_source >= 0)
1189           {
1190              ep->text.source = ed->table_parts[chosen_desc->text.id_source % ed->table_parts_size];
1191
1192              tmp = edje_string_get(&((Edje_Part_Description_Text *)ep->text.source->chosen_description)->text.style);
1193              if (tmp) style = tmp;
1194           }
1195         else
1196           {
1197              ep->text.source = NULL;
1198
1199              tmp = edje_string_get(&chosen_desc->text.style);
1200              if (tmp) style = tmp;
1201           }
1202
1203         if (chosen_desc->text.id_text_source >= 0)
1204           {
1205              ep->text.text_source = ed->table_parts[chosen_desc->text.id_text_source % ed->table_parts_size];
1206              text = edje_string_get(&((Edje_Part_Description_Text *)ep->text.text_source->chosen_description)->text.text);
1207
1208              if (ep->text.text_source->text.text) text = ep->text.text_source->text.text;
1209           }
1210         else
1211           {
1212              ep->text.text_source = NULL;
1213              text = edje_string_get(&chosen_desc->text.text);
1214              if (ep->text.text) text = ep->text.text;
1215           }
1216
1217         EINA_LIST_FOREACH(ed->file->styles, l, stl)
1218           {
1219              if ((stl->name) && (!strcmp(stl->name, style))) break;
1220              stl = NULL;
1221           }
1222
1223         if (ep->part->scale)
1224           evas_object_scale_set(ep->object, TO_DOUBLE(sc));
1225
1226         if (stl)
1227           {
1228              const char *ptxt;
1229
1230              if (evas_object_textblock_style_get(ep->object) != stl->style)
1231                evas_object_textblock_style_set(ep->object, stl->style);
1232              // FIXME: need to account for editing
1233              if (ep->part->entry_mode > EDJE_ENTRY_EDIT_MODE_NONE)
1234                {
1235                   // do nothing - should be done elsewhere
1236                }
1237              else
1238                {
1239                   ptxt = evas_object_textblock_text_markup_get(ep->object);
1240                   if (((!ptxt) && (text)) ||
1241                       ((ptxt) && (text) && (strcmp(ptxt, text))) ||
1242                       ((ptxt) && (!text)))
1243                     evas_object_textblock_text_markup_set(ep->object, text);
1244                }
1245              if ((chosen_desc->text.min_x) || (chosen_desc->text.min_y))
1246                {
1247                   int mw = 0, mh = 0;
1248
1249                   tw = th = 0;
1250                   if (!chosen_desc->text.min_x)
1251                     {
1252                        evas_object_resize(ep->object, params->w, params->h);
1253                        evas_object_textblock_size_formatted_get(ep->object, &tw,
1254                                                                 &th);
1255                     }
1256                   else
1257                     evas_object_textblock_size_native_get(ep->object, &tw, &th);
1258                   evas_object_textblock_style_insets_get(ep->object, &ins_l,
1259                                                          &ins_r, &ins_t, &ins_b);
1260                   mw = ins_l + tw + ins_r;
1261                   mh = ins_t + th + ins_b;
1262                   if (chosen_desc->text.min_x)
1263                     {
1264                        if (mw > *minw) *minw = mw;
1265                     }
1266                   if (chosen_desc->text.min_y)
1267                     {
1268                        if (mh > *minh) *minh = mh;
1269                     }
1270                }
1271           }
1272         if ((chosen_desc->text.max_x) || (chosen_desc->text.max_y))
1273           {
1274              int mw = 0, mh = 0;
1275
1276              tw = th = 0;
1277              if (!chosen_desc->text.max_x)
1278                {
1279                   evas_object_resize(ep->object, params->w, params->h);
1280                   evas_object_textblock_size_formatted_get(ep->object, &tw, &th);
1281                }
1282              else
1283                evas_object_textblock_size_native_get(ep->object, &tw, &th);
1284              evas_object_textblock_style_insets_get(ep->object, &ins_l, &ins_r,
1285                                                     &ins_t, &ins_b);
1286              mw = ins_l + tw + ins_r;
1287              mh = ins_t + th + ins_b;
1288              if (chosen_desc->text.max_x)
1289                {
1290                   if (mw > *maxw) *maxw = mw;
1291                   if (*maxw < *minw) *maxw = *minw;
1292                }
1293              if (chosen_desc->text.max_y)
1294                {
1295                   if (mh > *maxw) *maxh = mh;
1296                   if (*maxh < *minh) *maxh = *minh;
1297                }
1298           }
1299         if ((chosen_desc->text.fit_x) || (chosen_desc->text.fit_y))
1300           {
1301              double s = 1.0;
1302
1303              if (ep->part->scale) s = TO_DOUBLE(sc);
1304              evas_object_scale_set(ep->object, s);
1305              evas_object_textblock_size_formatted_get(ep->object, &tw, &th);
1306              if (chosen_desc->text.fit_x)
1307                {
1308                   if ((tw > 0) && (tw > params->w))
1309                     {
1310                        s = (s * params->w) / (double)tw;
1311                        evas_object_scale_set(ep->object, s);
1312                        evas_object_textblock_size_formatted_get(ep->object,
1313                                                                 &tw, &th);
1314                     }
1315                }
1316              if (chosen_desc->text.fit_y)
1317                {
1318                   if ((th > 0) && (th > params->h))
1319                     {
1320                        s = (s * params->h) / (double)th;
1321                        evas_object_scale_set(ep->object, s);
1322                        evas_object_textblock_size_formatted_get(ep->object,
1323                                                                 &tw, &th);
1324                     }
1325                }
1326           }
1327         evas_object_textblock_valign_set(ep->object, TO_DOUBLE(chosen_desc->text.align.y));
1328      }
1329 }
1330
1331 static void
1332 _edje_textblock_recalc_apply(Edje *ed, Edje_Real_Part *ep,
1333                              Edje_Calc_Params *params,
1334                              Edje_Part_Description_Text *chosen_desc)
1335 {
1336    /* FIXME: this is just an hack. */
1337    FLOAT_T sc;
1338    sc = ed->scale;
1339    if (sc == ZERO) sc = _edje_scale;
1340    if (chosen_desc->text.fit_x || chosen_desc->text.fit_y)
1341      {
1342         _edje_part_recalc_single_textblock(sc, ed, ep, chosen_desc, params,
1343                                            NULL, NULL, NULL, NULL);
1344      }
1345 }
1346
1347 static void
1348 _edje_part_recalc_single_text(FLOAT_T sc __UNUSED__,
1349                               Edje *ed,
1350                               Edje_Real_Part *ep,
1351                               Edje_Part_Description_Text *desc,
1352                               Edje_Part_Description_Text *chosen_desc,
1353                               Edje_Calc_Params *params,
1354                               int *minw, int *minh,
1355                               int *maxw, int *maxh)
1356 #define RECALC_SINGLE_TEXT_USING_APPLY 1
1357 #if RECALC_SINGLE_TEXT_USING_APPLY
1358 /*
1359  * XXX TODO NOTE:
1360  *
1361  * Original _edje_part_recalc_single_text() was not working as
1362  * expected since it was not doing size fit, range, ellipsis and so
1363  * on.
1364  *
1365  * The purpose of this function compared with
1366  * _edje_text_recalc_apply() is to be faster, not calling Evas update
1367  * functions. However for text this is quite difficult given that to
1368  * fit we need to set the font, size, style, etc. If it was done
1369  * correctly, we'd save some calls to move and some color sets,
1370  * however those shouldn't matter much in the overall picture.
1371  *
1372  * I've changed this to force applying the value, it should be more
1373  * correct and not so slow. The previous code is kept below for
1374  * reference but should be removed before next release!
1375  *
1376  * -- Gustavo Barbieri at 20-Aug-2011
1377  */
1378 {
1379    int tw, th, mw, mh, l, r, t, b, size;
1380    char *sfont = NULL;
1381
1382    _edje_text_class_font_get(ed, desc, &size, &sfont);
1383    free(sfont);
1384    params->type.text.size = size; /* XXX TODO used by further calcs, go inside recalc_apply? */
1385
1386    _edje_text_recalc_apply(ed, ep, params, chosen_desc);
1387
1388    evas_object_geometry_get(ep->object, NULL, NULL, &tw, &th);
1389
1390    if ((!chosen_desc) ||
1391        ((!chosen_desc->text.min_x) && (!chosen_desc->text.min_y) &&
1392         (!chosen_desc->text.max_x) && (!chosen_desc->text.max_y)))
1393      return;
1394
1395    evas_object_geometry_get(ep->object, NULL, NULL, &tw, &th);
1396    evas_object_text_style_pad_get(ep->object, &l, &r, &t, &b);
1397
1398    mw = tw + l + r;
1399    mh = th + t + b;
1400
1401    if (chosen_desc->text.max_x)
1402      {
1403         if ((*maxw < 0) || (mw < *maxw)) *maxw = mw;
1404      }
1405    if (chosen_desc->text.max_y)
1406      {
1407         if ((*maxh < 0) || (mh < *maxh)) *maxh = mh;
1408      }
1409    if (chosen_desc->text.min_x)
1410      {
1411         if (mw > *minw) *minw = mw;
1412      }
1413    if (chosen_desc->text.min_y)
1414      {
1415         if (mh > *minh) *minh = mh;
1416      }
1417 }
1418
1419 #else
1420 {
1421    char *sfont = NULL;
1422    int size;
1423
1424    if (chosen_desc)
1425      {
1426         const char *text;
1427         const char *font;
1428         Evas_Coord tw, th;
1429         int inlined_font = 0;
1430
1431         /* Update a object_text part */
1432
1433         if (chosen_desc->text.id_source >= 0)
1434           ep->text.source = ed->table_parts[chosen_desc->text.id_source % ed->table_parts_size];
1435         else
1436           ep->text.source = NULL;
1437
1438         if (chosen_desc->text.id_text_source >= 0)
1439           ep->text.text_source = ed->table_parts[chosen_desc->text.id_text_source % ed->table_parts_size];
1440         else
1441           ep->text.text_source = NULL;
1442
1443         if (ep->text.text_source)
1444           text = edje_string_get(&(((Edje_Part_Description_Text *)ep->text.text_source->chosen_description)->text.text));
1445         else
1446           text = edje_string_get(&chosen_desc->text.text);
1447
1448         if (ep->text.source)
1449           font = _edje_text_class_font_get(ed, ((Edje_Part_Description_Text *)ep->text.source->chosen_description), &size, &sfont);
1450         else
1451           font = _edje_text_class_font_get(ed, chosen_desc, &size, &sfont);
1452
1453         if (!font) font = "";
1454
1455         if (ep->text.text_source)
1456           {
1457              if (ep->text.text_source->text.text) text = ep->text.text_source->text.text;
1458           }
1459         else
1460           {
1461              if (ep->text.text) text = ep->text.text;
1462           }
1463
1464         if (ep->text.source)
1465           {
1466              if (ep->text.source->text.font) font = ep->text.source->text.font;
1467              if (ep->text.source->text.size > 0) size = ep->text.source->text.size;
1468           }
1469         else
1470           {
1471              if (ep->text.font) font = ep->text.font;
1472              if (ep->text.size > 0) size = ep->text.size;
1473           }
1474         if (!text) text = "";
1475
1476         /* check if the font is embedded in the .eet */
1477         if (ed->file->fonts)
1478           {
1479              Edje_Font_Directory_Entry *fnt;
1480
1481              fnt = eina_hash_find(ed->file->fonts, font);
1482
1483              if (fnt)
1484                {
1485                   char *font2;
1486
1487                   size_t len = strlen(font) + sizeof("edje/fonts/") + 1;
1488                   font2 = alloca(len);
1489                   sprintf(font2, "edje/fonts/%s", font);
1490                   font = font2;
1491                   inlined_font = 1;
1492                }
1493           }
1494         if (ep->part->scale)
1495           evas_object_scale_set(ep->object, TO_DOUBLE(sc));
1496         if (inlined_font)
1497           {
1498              evas_object_text_font_source_set(ep->object, ed->path);
1499           }
1500         else evas_object_text_font_source_set(ep->object, NULL);
1501
1502         if ((_edje_fontset_append) && (font))
1503           {
1504              char *font2;
1505
1506              font2 = malloc(strlen(font) + 1 + strlen(_edje_fontset_append) + 1);
1507              if (font2)
1508                {
1509                   strcpy(font2, font);
1510                   strcat(font2, ",");
1511                   strcat(font2, _edje_fontset_append);
1512                   evas_object_text_font_set(ep->object, font2, size);
1513                   free(font2);
1514                }
1515           }
1516         else
1517           evas_object_text_font_set(ep->object, font, size);
1518         if ((chosen_desc->text.min_x) || (chosen_desc->text.min_y) ||
1519             (chosen_desc->text.max_x) || (chosen_desc->text.max_y))
1520           {
1521              int mw, mh;
1522              Evas_Text_Style_Type
1523                style = EVAS_TEXT_STYLE_PLAIN,
1524                shadow = EVAS_TEXT_STYLE_SHADOW_DIRECTION_BOTTOM_RIGHT;
1525              const Evas_Text_Style_Type styles[] = {
1526                 EVAS_TEXT_STYLE_PLAIN,
1527                 EVAS_TEXT_STYLE_PLAIN,
1528                 EVAS_TEXT_STYLE_OUTLINE,
1529                 EVAS_TEXT_STYLE_SOFT_OUTLINE,
1530                 EVAS_TEXT_STYLE_SHADOW,
1531                 EVAS_TEXT_STYLE_SOFT_SHADOW,
1532                 EVAS_TEXT_STYLE_OUTLINE_SHADOW,
1533                 EVAS_TEXT_STYLE_OUTLINE_SOFT_SHADOW,
1534                 EVAS_TEXT_STYLE_FAR_SHADOW,
1535                 EVAS_TEXT_STYLE_FAR_SOFT_SHADOW,
1536                 EVAS_TEXT_STYLE_GLOW
1537              };
1538              const Evas_Text_Style_Type shadows[] = {
1539                 EVAS_TEXT_STYLE_SHADOW_DIRECTION_BOTTOM_RIGHT,
1540                 EVAS_TEXT_STYLE_SHADOW_DIRECTION_BOTTOM,
1541                 EVAS_TEXT_STYLE_SHADOW_DIRECTION_BOTTOM_LEFT,
1542                 EVAS_TEXT_STYLE_SHADOW_DIRECTION_LEFT,
1543                 EVAS_TEXT_STYLE_SHADOW_DIRECTION_TOP_LEFT,
1544                 EVAS_TEXT_STYLE_SHADOW_DIRECTION_TOP,
1545                 EVAS_TEXT_STYLE_SHADOW_DIRECTION_TOP_RIGHT,
1546                 EVAS_TEXT_STYLE_SHADOW_DIRECTION_RIGHT
1547              };
1548
1549              if ((ep->part->effect & EVAS_TEXT_STYLE_MASK_BASIC)
1550                  < EDJE_TEXT_EFFECT_LAST)
1551                style = styles[ep->part->effect];
1552              shadow = shadows
1553                [(ep->part->effect & EDJE_TEXT_EFFECT_MASK_SHADOW_DIRECTION) >> 4];
1554              EVAS_TEXT_STYLE_SHADOW_DIRECTION_SET(style, shadow);
1555
1556              evas_object_text_style_set(ep->object, style);
1557              evas_object_text_text_set(ep->object, text);
1558              evas_object_geometry_get(ep->object, NULL, NULL, &tw, &th);
1559              if (chosen_desc->text.max_x)
1560                {
1561                   int l, r;
1562                   evas_object_text_style_pad_get(ep->object, &l, &r, NULL, NULL);
1563                   mw = tw + l + r;
1564                   if ((*maxw < 0) || (mw < *maxw)) *maxw = mw;
1565                }
1566              if (chosen_desc->text.max_y)
1567                {
1568                   int t, b;
1569                   evas_object_text_style_pad_get(ep->object, NULL, NULL, &t, &b);
1570                   mh = th + t + b;
1571                   if ((*maxh < 0) || (mh < *maxh)) *maxh = mh;
1572                }
1573              if (chosen_desc->text.min_x)
1574                {
1575                   int l, r;
1576                   evas_object_text_style_pad_get(ep->object, &l, &r, NULL, NULL);
1577                   mw = tw + l + r;
1578                   if (mw > *minw) *minw = mw;
1579                }
1580              if (chosen_desc->text.min_y)
1581                {
1582                   int t, b;
1583                   evas_object_text_style_pad_get(ep->object, NULL, NULL, &t, &b);
1584                   mh = th + t + b;
1585                   if (mh > *minh) *minh = mh;
1586                }
1587           }
1588         if (sfont) free(sfont);
1589      }
1590
1591    /* FIXME: Do we really need to call it twice if chosen_desc ? */
1592    sfont = NULL;
1593    _edje_text_class_font_get(ed, desc, &size, &sfont);
1594    free(sfont);
1595    params->type.text.size = size;
1596 }
1597 #endif
1598
1599 static void
1600 _edje_part_recalc_single_min_length(FLOAT_T align, int *start, int *length, int min)
1601 {
1602    if (min >= 0)
1603      {
1604         if (*length < min)
1605           {
1606              *start += TO_INT(SCALE(align, (*length - min)));
1607              *length = min;
1608           }
1609      }
1610 }
1611
1612 static void
1613 _edje_part_recalc_single_min(Edje_Part_Description_Common *desc,
1614                              Edje_Calc_Params *params,
1615                              int minw, int minh,
1616                              Edje_Internal_Aspect aspect)
1617 {
1618    int tmp;
1619    int w;
1620    int h;
1621
1622    w = params->w ? params->w : 99999;
1623    h = params->h ? params->h : 99999;
1624
1625    switch (aspect)
1626      {
1627       case EDJE_ASPECT_PREFER_NONE:
1628         break;
1629
1630       case EDJE_ASPECT_PREFER_VERTICAL:
1631         tmp = minh * params->w / h;
1632         if (tmp >= minw)
1633           {
1634              minw = tmp;
1635              break;
1636           }
1637
1638       case EDJE_ASPECT_PREFER_HORIZONTAL:
1639         tmp = minw * params->h / w;
1640         if (tmp >= minh)
1641           {
1642              minh = tmp;
1643              break;
1644           }
1645
1646       case EDJE_ASPECT_PREFER_SOURCE:
1647       case EDJE_ASPECT_PREFER_BOTH:
1648         tmp = minh * params->w / h;
1649         if (tmp >= minw)
1650           {
1651              minw = tmp;
1652              break;
1653           }
1654
1655         tmp = minw * params->h / w;
1656         if (tmp >= minh)
1657           {
1658              minh = tmp;
1659              break;
1660           }
1661
1662         break;
1663      }
1664
1665    _edje_part_recalc_single_min_length(desc->align.x, &params->x, &params->w, minw);
1666    _edje_part_recalc_single_min_length(desc->align.y, &params->y, &params->h, minh);
1667 }
1668
1669 static void
1670 _edje_part_recalc_single_max_length(FLOAT_T align, int *start, int *length, int max)
1671 {
1672    if (max >= 0)
1673      {
1674         if (*length > max)
1675           {
1676              *start += TO_INT(SCALE(align, (*length - max)));
1677              *length = max;
1678           }
1679      }
1680 }
1681
1682 static void
1683 _edje_part_recalc_single_max(Edje_Part_Description_Common *desc,
1684                              Edje_Calc_Params *params,
1685                              int maxw, int maxh,
1686                              Edje_Internal_Aspect aspect)
1687 {
1688    int tmp;
1689    int w;
1690    int h;
1691
1692    w = params->w ? params->w : 99999;
1693    h = params->h ? params->h : 99999;
1694
1695    switch (aspect)
1696      {
1697       case EDJE_ASPECT_PREFER_NONE:
1698         break;
1699
1700       case EDJE_ASPECT_PREFER_VERTICAL:
1701         tmp = maxh * params->w / h;
1702         if (tmp <= maxw)
1703           {
1704              maxw = tmp;
1705              break;
1706           }
1707
1708       case EDJE_ASPECT_PREFER_HORIZONTAL:
1709         tmp = maxw * params->h / w;
1710         if (tmp <= maxh)
1711           {
1712              maxh = tmp;
1713              break;
1714           }
1715
1716       case EDJE_ASPECT_PREFER_SOURCE:
1717       case EDJE_ASPECT_PREFER_BOTH:
1718         tmp = maxh * params->w / h;
1719         if (tmp <= maxw)
1720           {
1721              maxw = tmp;
1722              break;
1723           }
1724
1725         tmp = maxw * params->h / w;
1726         if (tmp <= maxh)
1727           {
1728              maxh = tmp;
1729              break;
1730           }
1731
1732         break;
1733      }
1734
1735    _edje_part_recalc_single_max_length(desc->align.x, &params->x, &params->w, maxw);
1736    _edje_part_recalc_single_max_length(desc->align.y, &params->y, &params->h, maxh);
1737 }
1738
1739 static void
1740 _edje_part_recalc_single_drag(Edje_Real_Part *ep,
1741                               Edje_Real_Part *confine_to,
1742                               Edje_Calc_Params *params,
1743                               int minw, int minh,
1744                               int maxw, int maxh)
1745 {
1746    /* confine */
1747    if (confine_to)
1748      {
1749         int offset;
1750         int step;
1751         FLOAT_T v;
1752
1753         /* complex dragable params */
1754         v = SCALE(ep->drag->size.x, confine_to->w);
1755
1756         if ((minw > 0) && (TO_INT(v) < minw)) params->w = minw;
1757         else if ((maxw >= 0) && (TO_INT(v) > maxw))
1758           params->w = maxw;
1759         else params->w = TO_INT(v);
1760
1761         offset = TO_INT(SCALE(ep->drag->x, (confine_to->w - params->w)))
1762           + ep->drag->tmp.x;
1763         if (ep->part->dragable.step_x > 0)
1764           {
1765              params->x = confine_to->x +
1766                ((offset / ep->part->dragable.step_x) * ep->part->dragable.step_x);
1767           }
1768         else if (ep->part->dragable.count_x > 0)
1769           {
1770              step = (confine_to->w - params->w) / ep->part->dragable.count_x;
1771              if (step < 1) step = 1;
1772              params->x = confine_to->x +
1773                ((offset / step) * step);
1774           }
1775         params->req_drag.x = params->x;
1776         params->req_drag.w = params->w;
1777
1778         v = SCALE(ep->drag->size.y, confine_to->h);
1779
1780         if ((minh > 0) && (TO_INT(v) < minh)) params->h = minh;
1781         else if ((maxh >= 0) && (TO_INT(v) > maxh))
1782           params->h = maxh;
1783         else params->h = TO_INT(v);
1784
1785         offset = TO_INT(SCALE(ep->drag->y, (confine_to->h - params->h)))
1786           + ep->drag->tmp.y;
1787         if (ep->part->dragable.step_y > 0)
1788           {
1789              params->y = confine_to->y +
1790                ((offset / ep->part->dragable.step_y) * ep->part->dragable.step_y);
1791           }
1792         else if (ep->part->dragable.count_y > 0)
1793           {
1794              step = (confine_to->h - params->h) / ep->part->dragable.count_y;
1795              if (step < 1) step = 1;
1796              params->y = confine_to->y +
1797                ((offset / step) * step);
1798           }
1799         params->req_drag.y = params->y;
1800         params->req_drag.h = params->h;
1801
1802         /* limit to confine */
1803         if (params->x < confine_to->x)
1804           {
1805              params->x = confine_to->x;
1806           }
1807         if ((params->x + params->w) > (confine_to->x + confine_to->w))
1808           {
1809              params->x = confine_to->x + confine_to->w - params->w;
1810           }
1811         if (params->y < confine_to->y)
1812           {
1813              params->y = confine_to->y;
1814           }
1815         if ((params->y + params->h) > (confine_to->y + confine_to->h))
1816           {
1817              params->y = confine_to->y + confine_to->h - params->h;
1818           }
1819      }
1820    else
1821      {
1822         /* simple dragable params */
1823         params->x += TO_INT(ep->drag->x) + ep->drag->tmp.x;
1824         params->req_drag.x = params->x;
1825         params->req_drag.w = params->w;
1826
1827         params->y += TO_INT(ep->drag->y) + ep->drag->tmp.y;
1828         params->req_drag.y = params->y;
1829         params->req_drag.h = params->h;
1830      }
1831 }
1832
1833 static void
1834 _edje_part_recalc_single_fill(Edje_Real_Part *ep,
1835                               Edje_Part_Description_Spec_Fill *fill,
1836                               Edje_Calc_Params *params)
1837 {
1838    int fw;
1839    int fh;
1840
1841    params->smooth = fill->smooth;
1842
1843    if (fill->type == EDJE_FILL_TYPE_TILE)
1844      evas_object_image_size_get(ep->object, &fw, NULL);
1845    else
1846      fw = params->w;
1847
1848    params->type.common.fill.x = fill->pos_abs_x
1849      + TO_INT(SCALE(fill->pos_rel_x, fw));
1850    params->type.common.fill.w = fill->abs_x
1851      + TO_INT(SCALE(fill->rel_x, fw));
1852
1853    if (fill->type == EDJE_FILL_TYPE_TILE)
1854      evas_object_image_size_get(ep->object, NULL, &fh);
1855    else
1856      fh = params->h;
1857
1858    params->type.common.fill.y = fill->pos_abs_y
1859      + TO_INT(SCALE(fill->pos_rel_y, fh));
1860    params->type.common.fill.h = fill->abs_y
1861      + TO_INT(SCALE(fill->rel_y, fh));
1862
1863    params->type.common.fill.angle = fill->angle;
1864    params->type.common.fill.spread = fill->spread;
1865 }
1866
1867 static void
1868 _edje_part_recalc_single_min_max(FLOAT_T sc,
1869                                  Edje_Real_Part *ep,
1870                                  Edje_Part_Description_Common *desc,
1871                                  int *minw, int *minh,
1872                                  int *maxw, int *maxh)
1873 {
1874    *minw = desc->min.w;
1875    if (ep->part->scale) *minw = TO_INT(SCALE(sc, *minw));
1876    if (ep->swallow_params.min.w > desc->min.w)
1877      *minw = ep->swallow_params.min.w;
1878
1879    if (ep->edje->calc_only)
1880      {
1881         if (desc->minmul.have)
1882           {
1883              FLOAT_T mmw = desc->minmul.w;
1884              if (mmw != FROM_INT(1)) *minw = TO_INT(SCALE(mmw, *minw));
1885           }
1886      }
1887
1888    /* XXX TODO: remove need of EDJE_INF_MAX_W, see edje_util.c */
1889    if ((ep->swallow_params.max.w <= 0) ||
1890        (ep->swallow_params.max.w == EDJE_INF_MAX_W))
1891      {
1892         *maxw = desc->max.w;
1893         if (*maxw > 0)
1894           {
1895              if (ep->part->scale) *maxw = TO_INT(SCALE(sc, *maxw));
1896              if (*maxw < 1) *maxw = 1;
1897           }
1898      }
1899    else
1900      {
1901         if (desc->max.w <= 0)
1902           *maxw = ep->swallow_params.max.w;
1903         else
1904           {
1905              *maxw = desc->max.w;
1906              if (*maxw > 0)
1907                {
1908                   if (ep->part->scale) *maxw = TO_INT(SCALE(sc, *maxw));
1909                   if (*maxw < 1) *maxw = 1;
1910                }
1911              if (ep->swallow_params.max.w < *maxw)
1912                *maxw = ep->swallow_params.max.w;
1913           }
1914      }
1915    if ((ep->edje->calc_only) && (desc->minmul.have) &&
1916        (desc->minmul.w != FROM_INT(1))) *maxw = *minw;
1917    if (*maxw >= 0)
1918      {
1919         if (*maxw < *minw) *maxw = *minw;
1920      }
1921
1922    *minh = desc->min.h;
1923    if (ep->part->scale) *minh = TO_INT(SCALE(sc, *minh));
1924    if (ep->swallow_params.min.h > desc->min.h)
1925      *minh = ep->swallow_params.min.h;
1926
1927    if (ep->edje->calc_only)
1928      {
1929         if (desc->minmul.have)
1930           {
1931              FLOAT_T mmh = desc->minmul.h;
1932              if (mmh != FROM_INT(1)) *minh = TO_INT(SCALE(mmh, *minh));
1933           }
1934      }
1935
1936    /* XXX TODO: remove need of EDJE_INF_MAX_H, see edje_util.c */
1937    if ((ep->swallow_params.max.h <= 0) ||
1938        (ep->swallow_params.max.h == EDJE_INF_MAX_H))
1939      {
1940         *maxh = desc->max.h;
1941         if (*maxh > 0)
1942           {
1943              if (ep->part->scale) *maxh = TO_INT(SCALE(sc, *maxh));
1944              if (*maxh < 1) *maxh = 1;
1945           }
1946      }
1947    else
1948      {
1949         if (desc->max.h <= 0)
1950           *maxh = ep->swallow_params.max.h;
1951         else
1952           {
1953              *maxh = desc->max.h;
1954              if (*maxh > 0)
1955                {
1956                   if (ep->part->scale) *maxh = TO_INT(SCALE(sc, *maxh));
1957                   if (*maxh < 1) *maxh = 1;
1958                }
1959              if (ep->swallow_params.max.h < *maxh)
1960                *maxh = ep->swallow_params.max.h;
1961           }
1962      }
1963    if ((ep->edje->calc_only) && (desc->minmul.have) &&
1964        (desc->minmul.h != FROM_INT(1))) *maxh = *minh;
1965    if (*maxh >= 0)
1966      {
1967         if (*maxh < *minh) *maxh = *minh;
1968      }
1969 }
1970
1971 static void
1972 _edje_part_recalc_single_map(Edje *ed,
1973                              Edje_Real_Part *ep __UNUSED__,
1974                              Edje_Real_Part *center,
1975                              Edje_Real_Part *light,
1976                              Edje_Real_Part *persp,
1977                              Edje_Part_Description_Common *desc,
1978                              Edje_Part_Description_Common *chosen_desc,
1979                              Edje_Calc_Params *params)
1980 {
1981    params->mapped = chosen_desc->map.on;
1982    params->lighted = params->mapped ? !!light : 0;
1983    params->persp_on = params->mapped ? !!persp : 0;
1984
1985    if (!params->mapped) return;
1986
1987    if (center)
1988      {
1989         params->map.center.x = ed->x + center->x + (center->w / 2);
1990         params->map.center.y = ed->y + center->y + (center->h / 2);
1991      }
1992    else
1993      {
1994         params->map.center.x = ed->x + params->x + (params->w / 2);
1995         params->map.center.y = ed->y + params->y + (params->h / 2);
1996      }
1997    params->map.center.z = 0;
1998
1999    params->map.rotation.x = desc->map.rot.x;
2000    params->map.rotation.y = desc->map.rot.y;
2001    params->map.rotation.z = desc->map.rot.z;
2002
2003    if (light)
2004      {
2005         Edje_Part_Description_Common *light_desc2;
2006         FLOAT_T pos, pos2;
2007
2008         params->map.light.x = ed->x + light->x + (light->w / 2);
2009         params->map.light.y = ed->y + light->y + (light->h / 2);
2010
2011         pos = light->description_pos;
2012         pos2 = (pos < ZERO) ? ZERO : ((pos > FROM_INT(1)) ? FROM_INT(1) : pos);
2013
2014         light_desc2 = light->param2 ? light->param2->description : NULL;
2015
2016         /* take into account CURRENT state also */
2017         if (pos != ZERO && light_desc2)
2018           {
2019              params->map.light.z = light->param1.description->persp.zplane +
2020                TO_INT(SCALE(pos, light_desc2->persp.zplane - light->param1.description->persp.zplane));
2021              params->map.light.r = light->param1.description->color.r +
2022                TO_INT(SCALE(pos2, light_desc2->color.r - light->param1.description->color.r));
2023              params->map.light.g = light->param1.description->color.g +
2024                TO_INT(SCALE(pos2, light_desc2->color.g - light->param1.description->color.g));
2025              params->map.light.b = light->param1.description->color.b +
2026                TO_INT(SCALE(pos2, light_desc2->color.b - light->param1.description->color.b));
2027              params->map.light.ar = light->param1.description->color2.r +
2028                TO_INT(SCALE(pos2, light_desc2->color2.r - light->param1.description->color2.r));
2029              params->map.light.ag = light->param1.description->color2.g +
2030                TO_INT(SCALE(pos2, light_desc2->color2.g - light->param1.description->color2.g));
2031              params->map.light.ab = light->param1.description->color2.b +
2032                TO_INT(SCALE(pos2, light_desc2->color2.b - light->param1.description->color2.b));
2033           }
2034         else
2035           {
2036              params->map.light.z = light->param1.description->persp.zplane;
2037              params->map.light.r = light->param1.description->color.r;
2038              params->map.light.g = light->param1.description->color.g;
2039              params->map.light.b = light->param1.description->color.b;
2040              params->map.light.ar = light->param1.description->color2.r;
2041              params->map.light.ag = light->param1.description->color2.g;
2042              params->map.light.ab = light->param1.description->color2.b;
2043           }
2044      }
2045
2046    if (persp)
2047      {
2048         FLOAT_T pos;
2049
2050         params->map.persp.x = ed->x + persp->x + (persp->w / 2);
2051         params->map.persp.y = ed->y + persp->y + (persp->h / 2);
2052
2053         pos = persp->description_pos;
2054
2055         if (pos != 0 && persp->param2)
2056           {
2057              params->map.persp.z = persp->param1.description->persp.zplane +
2058                TO_INT(SCALE(pos, persp->param2->description->persp.zplane -
2059                             persp->param1.description->persp.zplane));
2060              params->map.persp.focal = persp->param1.description->persp.focal +
2061                TO_INT(SCALE(pos, persp->param2->description->persp.focal -
2062                             persp->param1.description->persp.focal));
2063           }
2064         else
2065           {
2066              params->map.persp.z = persp->param1.description->persp.zplane;
2067              params->map.persp.focal = persp->param1.description->persp.focal;
2068           }
2069      }
2070 }
2071
2072 static void
2073 _edje_part_recalc_single(Edje *ed,
2074                          Edje_Real_Part *ep,
2075                          Edje_Part_Description_Common *desc,
2076                          Edje_Part_Description_Common *chosen_desc,
2077                          Edje_Real_Part *center,
2078                          Edje_Real_Part *light,
2079                          Edje_Real_Part *persp,
2080                          Edje_Real_Part *rel1_to_x,
2081                          Edje_Real_Part *rel1_to_y,
2082                          Edje_Real_Part *rel2_to_x,
2083                          Edje_Real_Part *rel2_to_y,
2084                          Edje_Real_Part *confine_to,
2085                          Edje_Calc_Params *params,
2086                          FLOAT_T pos)
2087 {
2088    Edje_Color_Class *cc = NULL;
2089    Edje_Internal_Aspect apref;
2090    int minw = 0, minh = 0, maxw = 0, maxh = 0;
2091    FLOAT_T sc;
2092
2093    sc = ed->scale;
2094    if (sc == ZERO) sc = _edje_scale;
2095    _edje_part_recalc_single_min_max(sc, ep, desc, &minw, &minh, &maxw, &maxh);
2096
2097    /* relative coords of top left & bottom right */
2098    _edje_part_recalc_single_rel(ed, ep, desc, rel1_to_x, rel1_to_y, rel2_to_x, rel2_to_y, params);
2099
2100    /* aspect */
2101    apref = _edje_part_recalc_single_aspect(ed, ep, desc, params, &minw, &minh, &maxw, &maxh, pos);
2102
2103    /* size step */
2104    _edje_part_recalc_single_step(desc, params);
2105
2106    /* if we have text that wants to make the min size the text size... */
2107    if (ep->part->type == EDJE_PART_TYPE_TEXTBLOCK)
2108      _edje_part_recalc_single_textblock(sc, ed, ep, (Edje_Part_Description_Text *)chosen_desc, params, &minw, &minh, &maxw, &maxh);
2109    else if (ep->part->type == EDJE_PART_TYPE_TEXT)
2110      _edje_part_recalc_single_text(sc, ed, ep, (Edje_Part_Description_Text *)desc, (Edje_Part_Description_Text *)chosen_desc, params, &minw, &minh, &maxw, &maxh);
2111
2112    if ((ep->part->type == EDJE_PART_TYPE_TABLE) &&
2113        (((((Edje_Part_Description_Table *)chosen_desc)->table.min.h) ||
2114          (((Edje_Part_Description_Table *)chosen_desc)->table.min.v))))
2115      {
2116         Evas_Coord lminw = 0, lminh = 0;
2117
2118         evas_object_smart_need_recalculate_set(ep->object, 1);
2119         evas_object_smart_calculate(ep->object);
2120         evas_object_size_hint_min_get(ep->object, &lminw, &lminh);
2121         if (((Edje_Part_Description_Table *)chosen_desc)->table.min.h)
2122           {
2123              if (lminw > minw) minw = lminw;
2124           }
2125         if (((Edje_Part_Description_Table *)chosen_desc)->table.min.v)
2126           {
2127              if (lminh > minh) minh = lminh;
2128           }
2129      }
2130    else if ((ep->part->type == EDJE_PART_TYPE_BOX) &&
2131             ((((Edje_Part_Description_Box *)chosen_desc)->box.min.h) ||
2132              (((Edje_Part_Description_Box *)chosen_desc)->box.min.v)))
2133      {
2134         Evas_Coord lminw = 0, lminh = 0;
2135
2136         evas_object_smart_need_recalculate_set(ep->object, 1);
2137         evas_object_smart_calculate(ep->object);
2138         evas_object_size_hint_min_get(ep->object, &lminw, &lminh);
2139         if (((Edje_Part_Description_Box *)chosen_desc)->box.min.h)
2140           {
2141              if (lminw > minw) minw = lminw;
2142           }
2143         if (((Edje_Part_Description_Box *)chosen_desc)->box.min.v)
2144           {
2145              if (lminh > minh) minh = lminh;
2146           }
2147      }
2148    else if ((ep->part->type == EDJE_PART_TYPE_IMAGE) &&
2149             (chosen_desc->min.limit || chosen_desc->max.limit))
2150      {
2151         Evas_Coord w, h;
2152
2153         /* We only need pos to find the right image that would be displayed */
2154         /* Yes, if someone set aspect preference to SOURCE and also max,min
2155            to SOURCE, it will be under efficient, but who cares at the
2156            moment. */
2157         _edje_real_part_image_set(ed, ep, pos);
2158         evas_object_image_size_get(ep->object, &w, &h);
2159
2160         if (chosen_desc->min.limit)
2161           {
2162              if (w > minw) minw = w;
2163              if (h > minh) minh = h;
2164           }
2165         if (chosen_desc->max.limit)
2166           {
2167              if ((maxw <= 0) || (w < maxw)) maxw = w;
2168              if ((maxh <= 0) || (h < maxh)) maxh = h;
2169           }
2170      }
2171
2172    /* remember what our size is BEFORE we go limit it */
2173    params->req.x = params->x;
2174    params->req.y = params->y;
2175    params->req.w = params->w;
2176    params->req.h = params->h;
2177
2178    /* adjust for min size */
2179    _edje_part_recalc_single_min(desc, params, minw, minh, apref);
2180
2181    /* adjust for max size */
2182    _edje_part_recalc_single_max(desc, params, maxw, maxh, apref);
2183
2184    /* take care of dragable part */
2185    if (ep->drag)
2186      _edje_part_recalc_single_drag(ep, confine_to, params, minw, minh, maxw, maxh);
2187
2188    /* fill */
2189    if (ep->part->type == EDJE_PART_TYPE_IMAGE)
2190      _edje_part_recalc_single_fill(ep, &((Edje_Part_Description_Image *)desc)->image.fill, params);
2191    else if (ep->part->type == EDJE_PART_TYPE_PROXY)
2192      _edje_part_recalc_single_fill(ep, &((Edje_Part_Description_Proxy *)desc)->proxy.fill, params);
2193
2194    if (ep->part->type != EDJE_PART_TYPE_SPACER)
2195      {
2196         /* colors */
2197         if ((desc->color_class) && (*desc->color_class))
2198           cc = _edje_color_class_find(ed, desc->color_class);
2199
2200         if (cc)
2201           {
2202              params->color.r = (((int)cc->r + 1) * desc->color.r) >> 8;
2203              params->color.g = (((int)cc->g + 1) * desc->color.g) >> 8;
2204              params->color.b = (((int)cc->b + 1) * desc->color.b) >> 8;
2205              params->color.a = (((int)cc->a + 1) * desc->color.a) >> 8;
2206           }
2207         else
2208           {
2209              params->color.r = desc->color.r;
2210              params->color.g = desc->color.g;
2211              params->color.b = desc->color.b;
2212              params->color.a = desc->color.a;
2213           }
2214      }
2215
2216    /* visible */
2217    params->visible = desc->visible;
2218
2219    switch (ep->part->type)
2220      {
2221       case EDJE_PART_TYPE_IMAGE:
2222       {
2223          Edje_Part_Description_Image *img_desc = (Edje_Part_Description_Image *)desc;
2224
2225          /* border */
2226          params->type.common.spec.image.l = img_desc->image.border.l;
2227          params->type.common.spec.image.r = img_desc->image.border.r;
2228
2229          params->type.common.spec.image.t = img_desc->image.border.t;
2230          params->type.common.spec.image.b = img_desc->image.border.b;
2231
2232          params->type.common.spec.image.border_scale_by = img_desc->image.border.scale_by;
2233          break;
2234       }
2235
2236       case EDJE_PART_TYPE_TEXT:
2237       case EDJE_PART_TYPE_TEXTBLOCK:
2238       {
2239          Edje_Part_Description_Text *text_desc = (Edje_Part_Description_Text *)desc;
2240
2241          /* text.align */
2242          params->type.text.align.x = text_desc->text.align.x;
2243          params->type.text.align.y = text_desc->text.align.y;
2244          params->type.text.elipsis = text_desc->text.elipsis;
2245
2246          /* text colors */
2247          if (cc)
2248            {
2249               params->type.text.color2.r = (((int)cc->r2 + 1) * text_desc->common.color2.r) >> 8;
2250               params->type.text.color2.g = (((int)cc->g2 + 1) * text_desc->common.color2.g) >> 8;
2251               params->type.text.color2.b = (((int)cc->b2 + 1) * text_desc->common.color2.b) >> 8;
2252               params->type.text.color2.a = (((int)cc->a2 + 1) * text_desc->common.color2.a) >> 8;
2253               params->type.text.color3.r = (((int)cc->r3 + 1) * text_desc->text.color3.r) >> 8;
2254               params->type.text.color3.g = (((int)cc->g3 + 1) * text_desc->text.color3.g) >> 8;
2255               params->type.text.color3.b = (((int)cc->b3 + 1) * text_desc->text.color3.b) >> 8;
2256               params->type.text.color3.a = (((int)cc->a3 + 1) * text_desc->text.color3.a) >> 8;
2257            }
2258          else
2259            {
2260               params->type.text.color2.r = text_desc->common.color2.r;
2261               params->type.text.color2.g = text_desc->common.color2.g;
2262               params->type.text.color2.b = text_desc->common.color2.b;
2263               params->type.text.color2.a = text_desc->common.color2.a;
2264               params->type.text.color3.r = text_desc->text.color3.r;
2265               params->type.text.color3.g = text_desc->text.color3.g;
2266               params->type.text.color3.b = text_desc->text.color3.b;
2267               params->type.text.color3.a = text_desc->text.color3.a;
2268            }
2269
2270          break;
2271       }
2272
2273       case EDJE_PART_TYPE_SPACER:
2274       case EDJE_PART_TYPE_RECTANGLE:
2275       case EDJE_PART_TYPE_BOX:
2276       case EDJE_PART_TYPE_TABLE:
2277       case EDJE_PART_TYPE_SWALLOW:
2278       case EDJE_PART_TYPE_GROUP:
2279       case EDJE_PART_TYPE_PROXY:
2280         break;
2281
2282       case EDJE_PART_TYPE_GRADIENT:
2283         /* FIXME: THIS ONE SHOULD NEVER BE TRIGGERED. */
2284         break;
2285
2286       default:
2287         break;
2288      }
2289
2290    _edje_part_recalc_single_map(ed, ep, center, light, persp, desc, chosen_desc, params);
2291 }
2292
2293 static void
2294 _edje_table_recalc_apply(Edje *ed __UNUSED__,
2295                          Edje_Real_Part *ep,
2296                          Edje_Calc_Params *p3 __UNUSED__,
2297                          Edje_Part_Description_Table *chosen_desc)
2298 {
2299    evas_object_table_homogeneous_set(ep->object, chosen_desc->table.homogeneous);
2300    evas_object_table_align_set(ep->object, TO_DOUBLE(chosen_desc->table.align.x), TO_DOUBLE(chosen_desc->table.align.y));
2301    evas_object_table_padding_set(ep->object, chosen_desc->table.padding.x, chosen_desc->table.padding.y);
2302    if (evas_object_smart_need_recalculate_get(ep->object))
2303      {
2304         evas_object_smart_need_recalculate_set(ep->object, 0);
2305         evas_object_smart_calculate(ep->object);
2306      }
2307 }
2308
2309 static void
2310 _edje_proxy_recalc_apply(Edje *ed, Edje_Real_Part *ep, Edje_Calc_Params *p3, Edje_Part_Description_Proxy *chosen_desc, FLOAT_T pos)
2311 {
2312    Edje_Real_Part *pp;
2313    int part_id = -1;
2314
2315    if (pos >= FROM_DOUBLE(0.5))
2316      part_id = ((Edje_Part_Description_Proxy *)ep->param2->description)->proxy.id;
2317    else
2318      part_id = chosen_desc->proxy.id;
2319
2320    if ((p3->type.common.fill.w == 0) || (p3->type.common.fill.h == 0) ||
2321        (part_id < 0))
2322      {
2323         evas_object_image_source_set(ep->object, NULL);
2324         return;
2325      }
2326    pp = ed->table_parts[part_id % ed->table_parts_size];
2327
2328    switch (pp->part->type)
2329      {
2330       case EDJE_PART_TYPE_IMAGE:
2331       case EDJE_PART_TYPE_TEXT:
2332       case EDJE_PART_TYPE_TEXTBLOCK:
2333       case EDJE_PART_TYPE_RECTANGLE:
2334       case EDJE_PART_TYPE_BOX:
2335       case EDJE_PART_TYPE_TABLE:
2336       case EDJE_PART_TYPE_PROXY:
2337         evas_object_image_source_set(ep->object, pp->object);
2338         break;
2339
2340       case EDJE_PART_TYPE_GRADIENT:
2341         /* FIXME: THIS ONE SHOULD NEVER BE TRIGGERED. */
2342         break;
2343
2344       case EDJE_PART_TYPE_GROUP:
2345       case EDJE_PART_TYPE_SWALLOW:
2346       case EDJE_PART_TYPE_EXTERNAL:
2347         evas_object_image_source_set(ep->object, pp->swallowed_object);
2348         break;
2349
2350       case EDJE_PART_TYPE_SPACER:
2351         /* FIXME: detect that at compile time and prevent it */
2352         break;
2353      }
2354
2355    evas_object_image_fill_set(ep->object, p3->type.common.fill.x, p3->type.common.fill.y,
2356                               p3->type.common.fill.w, p3->type.common.fill.h);
2357    evas_object_image_smooth_scale_set(ep->object, p3->smooth);
2358 }
2359
2360 static void
2361 _edje_image_recalc_apply(Edje *ed, Edje_Real_Part *ep, Edje_Calc_Params *p3, Edje_Part_Description_Image *chosen_desc, FLOAT_T pos)
2362 {
2363    FLOAT_T sc;
2364
2365    sc = ed->scale;
2366    if (sc == 0.0) sc = _edje_scale;
2367    evas_object_image_fill_set(ep->object, p3->type.common.fill.x, p3->type.common.fill.y,
2368                               p3->type.common.fill.w, p3->type.common.fill.h);
2369    evas_object_image_smooth_scale_set(ep->object, p3->smooth);
2370    if (chosen_desc->image.border.scale)
2371      {
2372         if (p3->type.common.spec.image.border_scale_by > FROM_DOUBLE(0.0))
2373           {
2374              FLOAT_T sc2 = MUL(sc, p3->type.common.spec.image.border_scale_by);
2375              evas_object_image_border_scale_set(ep->object, TO_DOUBLE(sc2));
2376           }
2377         else
2378           evas_object_image_border_scale_set(ep->object, TO_DOUBLE(sc));
2379      }
2380    else
2381      {
2382         if (p3->type.common.spec.image.border_scale_by > FROM_DOUBLE(0.0))
2383           evas_object_image_border_scale_set
2384             (ep->object, TO_DOUBLE(p3->type.common.spec.image.border_scale_by));
2385         else
2386           evas_object_image_border_scale_set(ep->object, 1.0);
2387      }
2388    evas_object_image_border_set(ep->object, p3->type.common.spec.image.l, p3->type.common.spec.image.r,
2389                                 p3->type.common.spec.image.t, p3->type.common.spec.image.b);
2390    if (chosen_desc->image.border.no_fill == 0)
2391      evas_object_image_border_center_fill_set(ep->object, EVAS_BORDER_FILL_DEFAULT);
2392    else if (chosen_desc->image.border.no_fill == 1)
2393      evas_object_image_border_center_fill_set(ep->object, EVAS_BORDER_FILL_NONE);
2394    else if (chosen_desc->image.border.no_fill == 2)
2395      evas_object_image_border_center_fill_set(ep->object, EVAS_BORDER_FILL_SOLID);
2396
2397    _edje_real_part_image_set(ed, ep, pos);
2398 }
2399
2400 static Edje_Real_Part *
2401 _edje_real_part_state_get(Edje *ed, Edje_Real_Part *ep, int flags, int id, int *state)
2402 {
2403    Edje_Real_Part *result = NULL;
2404
2405    if (id >= 0 && id != ep->part->id)
2406      {
2407         result = ed->table_parts[id % ed->table_parts_size];
2408         if (result)
2409           {
2410              if (!result->calculated) _edje_part_recalc(ed, result, flags, NULL);
2411 #ifdef EDJE_CALC_CACHE
2412              if (state) *state = result->state;
2413 #else
2414              (void)state;
2415 #endif
2416           }
2417      }
2418    return result;
2419 }
2420
2421 void
2422 _edje_part_recalc(Edje *ed, Edje_Real_Part *ep, int flags, Edje_Calc_Params *state)
2423 {
2424 #ifdef EDJE_CALC_CACHE
2425    Eina_Bool proxy_invalidate = EINA_FALSE;
2426    int state1 = -1;
2427    int state2 = -1;
2428    int statec = -1;
2429 #else
2430    Edje_Calc_Params lp1, lp2;
2431 #endif
2432    int statec1 = -1;
2433    int statec2 = -1;
2434    int statel1 = -1;
2435    int statel2 = -1;
2436    int statep1 = -1;
2437    int statep2 = -1;
2438    Edje_Real_Part *center[2] = { NULL, NULL };
2439    Edje_Real_Part *light[2] = { NULL, NULL };
2440    Edje_Real_Part *persp[2] = { NULL, NULL };
2441    Edje_Calc_Params *p1, *pf;
2442    Edje_Part_Description_Common *chosen_desc;
2443    Edje_Real_Part *confine_to = NULL;
2444    FLOAT_T pos = ZERO, pos2;
2445    Edje_Calc_Params lp3;
2446
2447    /* GRADIENT ARE GONE, WE MUST IGNORE IT FROM OLD FILE. */
2448    if (ep->part->type == EDJE_PART_TYPE_GRADIENT)
2449      {
2450         ERR("GRADIENT spotted during recalc ! That should never happen ! Send your edje file to devel ml.");
2451         return;
2452      }
2453
2454    if ((ep->calculated & FLAG_XY) == FLAG_XY && !state)
2455      {
2456         return;
2457      }
2458    if (ep->calculating & flags)
2459      {
2460 #if 1
2461         const char *axes = "NONE", *faxes = "NONE";
2462
2463         if ((ep->calculating & FLAG_X) &&
2464             (ep->calculating & FLAG_Y))
2465           axes = "XY";
2466         else if ((ep->calculating & FLAG_X))
2467           axes = "X";
2468         else if ((ep->calculating & FLAG_Y))
2469           axes = "Y";
2470
2471         if ((flags & FLAG_X) &&
2472             (flags & FLAG_Y))
2473           faxes = "XY";
2474         else if ((flags & FLAG_X))
2475           faxes = "X";
2476         else if ((flags & FLAG_Y))
2477           faxes = "Y";
2478         ERR("Circular dependency when calculating part \"%s\". "
2479             "Already calculating %s [%02x] axes. "
2480             "Need to calculate %s [%02x] axes",
2481             ep->part->name,
2482             axes, ep->calculating,
2483             faxes, flags);
2484 #endif
2485         return;
2486      }
2487
2488    if (ep->part->scale &&
2489        ep->part->type == EDJE_PART_TYPE_GROUP &&
2490        ep->swallowed_object)
2491      {
2492         edje_object_scale_set(ep->swallowed_object, TO_DOUBLE(ed->scale));
2493
2494         if (ep->description_pos > FROM_DOUBLE(0.5) && ep->param2)
2495           {
2496              edje_object_update_hints_set(ep->swallowed_object, ep->param2->description->min.limit);
2497           }
2498         else
2499           {
2500              edje_object_update_hints_set(ep->swallowed_object, ep->param1.description->min.limit);
2501           }
2502         if (edje_object_update_hints_get(ep->swallowed_object))
2503           {
2504              Edje *ted;
2505
2506              ted = _edje_fetch(ep->swallowed_object);
2507              _edje_recalc_do(ted);
2508           }
2509      }
2510
2511 #ifdef EDJE_CALC_CACHE
2512    if (ep->state == ed->state && !state)
2513      return;
2514 #endif
2515
2516    if (flags & FLAG_X)
2517      {
2518         ep->calculating |= flags & FLAG_X;
2519         if (ep->param1.rel1_to_x)
2520           {
2521              _edje_part_recalc(ed, ep->param1.rel1_to_x, FLAG_X, NULL);
2522 #ifdef EDJE_CALC_CACHE
2523              state1 = ep->param1.rel1_to_x->state;
2524 #endif
2525           }
2526         if (ep->param1.rel2_to_x)
2527           {
2528              _edje_part_recalc(ed, ep->param1.rel2_to_x, FLAG_X, NULL);
2529 #ifdef EDJE_CALC_CACHE
2530              if (state1 < ep->param1.rel2_to_x->state)
2531                state1 = ep->param1.rel2_to_x->state;
2532 #endif
2533           }
2534         if (ep->param2)
2535           {
2536              if (ep->param2->rel1_to_x)
2537                {
2538                   _edje_part_recalc(ed, ep->param2->rel1_to_x, FLAG_X, NULL);
2539 #ifdef EDJE_CALC_CACHE
2540                   state2 = ep->param2->rel1_to_x->state;
2541 #endif
2542                }
2543              if (ep->param2->rel2_to_x)
2544                {
2545                   _edje_part_recalc(ed, ep->param2->rel2_to_x, FLAG_X, NULL);
2546 #ifdef EDJE_CALC_CACHE
2547                   if (state2 < ep->param2->rel2_to_x->state)
2548                     state2 = ep->param2->rel2_to_x->state;
2549 #endif
2550                }
2551           }
2552      }
2553    if (flags & FLAG_Y)
2554      {
2555         ep->calculating |= flags & FLAG_Y;
2556         if (ep->param1.rel1_to_y)
2557           {
2558              _edje_part_recalc(ed, ep->param1.rel1_to_y, FLAG_Y, NULL);
2559 #ifdef EDJE_CALC_CACHE
2560              if (state1 < ep->param1.rel1_to_y->state)
2561                state1 = ep->param1.rel1_to_y->state;
2562 #endif
2563           }
2564         if (ep->param1.rel2_to_y)
2565           {
2566              _edje_part_recalc(ed, ep->param1.rel2_to_y, FLAG_Y, NULL);
2567 #ifdef EDJE_CALC_CACHE
2568              if (state1 < ep->param1.rel2_to_y->state)
2569                state1 = ep->param1.rel2_to_y->state;
2570 #endif
2571           }
2572         if (ep->param2)
2573           {
2574              if (ep->param2->rel1_to_y)
2575                {
2576                   _edje_part_recalc(ed, ep->param2->rel1_to_y, FLAG_Y, NULL);
2577 #ifdef EDJE_CALC_CACHE
2578                   if (state2 < ep->param2->rel1_to_y->state)
2579                     state2 = ep->param2->rel1_to_y->state;
2580 #endif
2581                }
2582              if (ep->param2->rel2_to_y)
2583                {
2584                   _edje_part_recalc(ed, ep->param2->rel2_to_y, FLAG_Y, NULL);
2585 #ifdef EDJE_CALC_CACHE
2586                   if (state2 < ep->param2->rel2_to_y->state)
2587                     state2 = ep->param2->rel2_to_y->state;
2588 #endif
2589                }
2590           }
2591      }
2592    if (ep->drag && ep->drag->confine_to)
2593      {
2594         confine_to = ep->drag->confine_to;
2595         _edje_part_recalc(ed, confine_to, flags, NULL);
2596 #ifdef EDJE_CALC_CACHE
2597         statec = confine_to->state;
2598 #endif
2599      }
2600    //   if (ep->text.source)       _edje_part_recalc(ed, ep->text.source, flags);
2601    //   if (ep->text.text_source)  _edje_part_recalc(ed, ep->text.text_source, flags);
2602
2603    /* actually calculate now */
2604    chosen_desc = ep->chosen_description;
2605    if (!chosen_desc)
2606      {
2607         ep->calculating = FLAG_NONE;
2608         ep->calculated |= flags;
2609         return;
2610      }
2611
2612    pos = ep->description_pos;
2613
2614    if (ep->part->type == EDJE_PART_TYPE_PROXY)
2615      {
2616         Edje_Real_Part *pp;
2617         int part_id = -1;
2618
2619         if (pos >= FROM_DOUBLE(0.5))
2620           part_id = ((Edje_Part_Description_Proxy *)ep->param2->description)->proxy.id;
2621         else
2622           part_id = ((Edje_Part_Description_Proxy *)chosen_desc)->proxy.id;
2623
2624         pp = _edje_real_part_state_get(ed, ep, flags, part_id, NULL);
2625 #ifdef EDJE_CALC_CACHE
2626         if (pp && pp->invalidate) proxy_invalidate = EINA_TRUE;
2627 #endif
2628      }
2629
2630    /* Recalc if needed the map center && light source */
2631    if (ep->param1.description->map.on)
2632      {
2633         center[0] = _edje_real_part_state_get(ed, ep, flags, ep->param1.description->map.rot.id_center, &statec1);
2634         light[0] = _edje_real_part_state_get(ed, ep, flags, ep->param1.description->map.id_light, &statel1);
2635
2636         if (chosen_desc->map.persp_on)
2637           {
2638              persp[0] = _edje_real_part_state_get(ed, ep, flags, ep->param1.description->map.id_persp, &statep1);
2639           }
2640      }
2641
2642    if (ep->param2 && ep->param2->description->map.on)
2643      {
2644         center[1] = _edje_real_part_state_get(ed, ep, flags, ep->param2->description->map.rot.id_center, &statec2);
2645         light[1] = _edje_real_part_state_get(ed, ep, flags, ep->param2->description->map.id_light, &statel2);
2646
2647         if (chosen_desc->map.persp_on)
2648           {
2649              persp[1] = _edje_real_part_state_get(ed, ep, flags, ep->param2->description->map.id_persp, &statep2);
2650           }
2651      }
2652
2653 #ifndef EDJE_CALC_CACHE
2654    p1 = &lp1;
2655 #else
2656    p1 = &ep->param1.p;
2657 #endif
2658
2659    if (ep->param1.description)
2660      {
2661 #ifdef EDJE_CALC_CACHE
2662         if (ed->all_part_change ||
2663             ep->invalidate ||
2664             state1 >= ep->param1.state ||
2665             statec >= ep->param1.state ||
2666             statec1 >= ep->param1.state ||
2667             statel1 >= ep->param1.state ||
2668             statep1 >= ep->param1.state ||
2669             proxy_invalidate ||
2670             state ||
2671             ((ep->part->type == EDJE_PART_TYPE_TEXT || ep->part->type == EDJE_PART_TYPE_TEXTBLOCK) && ed->text_part_change))
2672 #endif
2673         {
2674            _edje_part_recalc_single(ed, ep, ep->param1.description, chosen_desc, center[0], light[0], persp[0],
2675                                     ep->param1.rel1_to_x, ep->param1.rel1_to_y, ep->param1.rel2_to_x, ep->param1.rel2_to_y,
2676                                     confine_to,
2677                                     p1, pos);
2678
2679 #ifdef EDJE_CALC_CACHE
2680            if (flags == FLAG_XY)
2681              ep->param1.state = ed->state;
2682 #endif
2683         }
2684      }
2685    if (ep->param2)
2686      {
2687         int beginning_pos, part_type;
2688         Edje_Calc_Params *p2, *p3;
2689
2690         if (ep->current)
2691           {
2692              /* FIXME: except for text, we don't need in that case to recalc p1 at all*/
2693              memcpy(p1, ep->current, sizeof (Edje_Calc_Params));
2694           }
2695
2696         p3 = &lp3;
2697
2698 #ifndef EDJE_CALC_CACHE
2699         p2 = &lp2;
2700 #else
2701         p2 = &ep->param2->p;
2702
2703         if (ed->all_part_change ||
2704             ep->invalidate ||
2705             state2 >= ep->param2->state ||
2706             statec >= ep->param2->state ||
2707             statec2 >= ep->param2->state ||
2708             statel2 >= ep->param2->state ||
2709             statep2 >= ep->param2->state ||
2710             proxy_invalidate ||
2711             state ||
2712             ((ep->part->type == EDJE_PART_TYPE_TEXT || ep->part->type == EDJE_PART_TYPE_TEXTBLOCK) && ed->text_part_change))
2713 #endif
2714         {
2715            _edje_part_recalc_single(ed, ep, ep->param2->description,
2716                                     chosen_desc,
2717                                     center[1], light[1], persp[1],
2718                                     ep->param2->rel1_to_x,
2719                                     ep->param2->rel1_to_y,
2720                                     ep->param2->rel2_to_x,
2721                                     ep->param2->rel2_to_y,
2722                                     confine_to,
2723                                     p2, pos);
2724 #ifdef EDJE_CALC_CACHE
2725            if (flags == FLAG_XY)
2726              ep->param2->state = ed->state;
2727 #endif
2728         }
2729
2730         pos2 = pos;
2731         if (pos2 < ZERO) pos2 = ZERO;
2732         else if (pos2 > FROM_INT(1))
2733           pos2 = FROM_INT(1);
2734         beginning_pos = (pos < FROM_DOUBLE(0.5));
2735         part_type = ep->part->type;
2736
2737         /* visible is special */
2738         if ((p1->visible) && (!p2->visible))
2739           p3->visible = (pos != FROM_INT(1));
2740         else if ((!p1->visible) && (p2->visible))
2741           p3->visible = (pos != ZERO);
2742         else
2743           p3->visible = p1->visible;
2744
2745         p3->smooth = (beginning_pos) ? p1->smooth : p2->smooth;
2746
2747         /* FIXME: do x and y separately base on flag */
2748 #define FINTP(_x1, _x2, _p) \
2749   (((_x1) == (_x2))         \
2750    ? FROM_INT((_x1))        \
2751    : ADD(FROM_INT(_x1),     \
2752          SCALE((_p), (_x2) - (_x1))))
2753
2754 #define FFP(_x1, _x2, _p) \
2755   (((_x1) == (_x2))       \
2756    ? (_x1)                \
2757    : ADD(_x1, MUL(_p, SUB(_x2, _x1))));
2758
2759 #define INTP(_x1, _x2, _p) TO_INT(FINTP(_x1, _x2, _p))
2760
2761         p3->x = INTP(p1->x, p2->x, pos);
2762         p3->y = INTP(p1->y, p2->y, pos);
2763         p3->w = INTP(p1->w, p2->w, pos);
2764         p3->h = INTP(p1->h, p2->h, pos);
2765
2766         p3->req.x = INTP(p1->req.x, p2->req.x, pos);
2767         p3->req.y = INTP(p1->req.y, p2->req.y, pos);
2768         p3->req.w = INTP(p1->req.w, p2->req.w, pos);
2769         p3->req.h = INTP(p1->req.h, p2->req.h, pos);
2770
2771         if (ep->part->dragable.x)
2772           {
2773              p3->req_drag.x = INTP(p1->req_drag.x, p2->req_drag.x, pos);
2774              p3->req_drag.w = INTP(p1->req_drag.w, p2->req_drag.w, pos);
2775           }
2776         if (ep->part->dragable.y)
2777           {
2778              p3->req_drag.y = INTP(p1->req_drag.y, p2->req_drag.y, pos);
2779              p3->req_drag.h = INTP(p1->req_drag.h, p2->req_drag.h, pos);
2780           }
2781
2782         p3->color.r = INTP(p1->color.r, p2->color.r, pos2);
2783         p3->color.g = INTP(p1->color.g, p2->color.g, pos2);
2784         p3->color.b = INTP(p1->color.b, p2->color.b, pos2);
2785         p3->color.a = INTP(p1->color.a, p2->color.a, pos2);
2786
2787         switch (part_type)
2788           {
2789            case EDJE_PART_TYPE_IMAGE:
2790              p3->type.common.spec.image.l = INTP(p1->type.common.spec.image.l, p2->type.common.spec.image.l, pos);
2791              p3->type.common.spec.image.r = INTP(p1->type.common.spec.image.r, p2->type.common.spec.image.r, pos);
2792              p3->type.common.spec.image.t = INTP(p1->type.common.spec.image.t, p2->type.common.spec.image.t, pos);
2793              p3->type.common.spec.image.b = INTP(p1->type.common.spec.image.b, p2->type.common.spec.image.b, pos);
2794              p3->type.common.spec.image.border_scale_by = INTP(p1->type.common.spec.image.border_scale_by, p2->type.common.spec.image.border_scale_by, pos);
2795
2796            case EDJE_PART_TYPE_PROXY:
2797              p3->type.common.fill.x = INTP(p1->type.common.fill.x, p2->type.common.fill.x, pos);
2798              p3->type.common.fill.y = INTP(p1->type.common.fill.y, p2->type.common.fill.y, pos);
2799              p3->type.common.fill.w = INTP(p1->type.common.fill.w, p2->type.common.fill.w, pos);
2800              p3->type.common.fill.h = INTP(p1->type.common.fill.h, p2->type.common.fill.h, pos);
2801              break;
2802
2803            case EDJE_PART_TYPE_TEXT:
2804              p3->type.text.size = INTP(p1->type.text.size, p2->type.text.size, pos);
2805
2806            case EDJE_PART_TYPE_TEXTBLOCK:
2807              p3->type.text.color2.r = INTP(p1->type.text.color2.r, p2->type.text.color2.r, pos2);
2808              p3->type.text.color2.g = INTP(p1->type.text.color2.g, p2->type.text.color2.g, pos2);
2809              p3->type.text.color2.b = INTP(p1->type.text.color2.b, p2->type.text.color2.b, pos2);
2810              p3->type.text.color2.a = INTP(p1->type.text.color2.a, p2->type.text.color2.a, pos2);
2811
2812              p3->type.text.color3.r = INTP(p1->type.text.color3.r, p2->type.text.color3.r, pos2);
2813              p3->type.text.color3.g = INTP(p1->type.text.color3.g, p2->type.text.color3.g, pos2);
2814              p3->type.text.color3.b = INTP(p1->type.text.color3.b, p2->type.text.color3.b, pos2);
2815              p3->type.text.color3.a = INTP(p1->type.text.color3.a, p2->type.text.color3.a, pos2);
2816
2817              p3->type.text.align.x = FFP(p1->type.text.align.x, p2->type.text.align.x, pos);
2818              p3->type.text.align.y = FFP(p1->type.text.align.y, p2->type.text.align.y, pos);
2819              p3->type.text.elipsis = TO_DOUBLE(FINTP(p1->type.text.elipsis, p2->type.text.elipsis, pos2));
2820              break;
2821           }
2822
2823         p3->mapped = p1->mapped;
2824         p3->persp_on = p3->mapped ? p1->persp_on | p2->persp_on : 0;
2825         p3->lighted = p3->mapped ? p1->lighted | p2->lighted : 0;
2826         if (p1->mapped)
2827           {
2828              p3->map.center.x = INTP(p1->map.center.x, p2->map.center.x, pos);
2829              p3->map.center.y = INTP(p1->map.center.y, p2->map.center.y, pos);
2830              p3->map.center.z = INTP(p1->map.center.z, p2->map.center.z, pos);
2831              p3->map.rotation.x = FFP(p1->map.rotation.x, p2->map.rotation.x, pos);
2832              p3->map.rotation.y = FFP(p1->map.rotation.y, p2->map.rotation.y, pos);
2833              p3->map.rotation.z = FFP(p1->map.rotation.z, p2->map.rotation.z, pos);
2834
2835 #define MIX(P1, P2, P3, pos, info) \
2836   P3->info = P1->info + TO_INT(SCALE(pos, P2->info - P1->info));
2837
2838              if (p1->lighted && p2->lighted)
2839                {
2840                   MIX(p1, p2, p3, pos, map.light.x);
2841                   MIX(p1, p2, p3, pos, map.light.y);
2842                   MIX(p1, p2, p3, pos, map.light.z);
2843                   MIX(p1, p2, p3, pos, map.light.r);
2844                   MIX(p1, p2, p3, pos, map.light.g);
2845                   MIX(p1, p2, p3, pos, map.light.b);
2846                   MIX(p1, p2, p3, pos, map.light.ar);
2847                   MIX(p1, p2, p3, pos, map.light.ag);
2848                   MIX(p1, p2, p3, pos, map.light.ab);
2849                }
2850              else if (p1->lighted)
2851                {
2852                   memcpy(&p3->map.light, &p1->map.light, sizeof (p1->map.light));
2853                }
2854              else if (p2->lighted)
2855                {
2856                   memcpy(&p3->map.light, &p2->map.light, sizeof (p2->map.light));
2857                }
2858
2859              if (p1->persp_on && p2->persp_on)
2860                {
2861                   MIX(p1, p2, p3, pos, map.persp.x);
2862                   MIX(p1, p2, p3, pos, map.persp.y);
2863                   MIX(p1, p2, p3, pos, map.persp.z);
2864                   MIX(p1, p2, p3, pos, map.persp.focal);
2865                }
2866              else if (p1->persp_on)
2867                {
2868                   memcpy(&p3->map.persp, &p1->map.persp, sizeof (p1->map.persp));
2869                }
2870              else if (p2->persp_on)
2871                {
2872                   memcpy(&p3->map.persp, &p2->map.persp, sizeof (p2->map.persp));
2873                }
2874           }
2875
2876         pf = p3;
2877      }
2878    else
2879      {
2880         pf = p1;
2881      }
2882
2883    if (!pf->persp_on && chosen_desc->map.persp_on)
2884      {
2885         if (ed->persp)
2886           {
2887              pf->map.persp.x = ed->persp->px;
2888              pf->map.persp.y = ed->persp->py;
2889              pf->map.persp.z = ed->persp->z0;
2890              pf->map.persp.focal = ed->persp->foc;
2891           }
2892         else
2893           {
2894              const Edje_Perspective *ps;
2895
2896              // fixme: a tad inefficient as this is a has lookup
2897              ps = edje_object_perspective_get(ed->obj);
2898              if (!ps)
2899                ps = edje_evas_global_perspective_get(evas_object_evas_get(ed->obj));
2900              if (ps)
2901                {
2902                   pf->map.persp.x = ps->px;
2903                   pf->map.persp.y = ps->py;
2904                   pf->map.persp.z = ps->z0;
2905                   pf->map.persp.focal = ps->foc;
2906                }
2907              else
2908                {
2909                   pf->map.persp.x = ed->x + (ed->w / 2);
2910                   pf->map.persp.y = ed->y + (ed->h / 2);
2911                   pf->map.persp.z = 0;
2912                   pf->map.persp.focal = 1000;
2913                }
2914           }
2915      }
2916
2917    if (state)
2918      {
2919         memcpy(state, pf, sizeof (Edje_Calc_Params));
2920      }
2921
2922    ep->req = pf->req;
2923
2924    if (ep->drag && ep->drag->need_reset)
2925      {
2926         FLOAT_T dx, dy;
2927
2928         dx = ZERO;
2929         dy = ZERO;
2930         _edje_part_dragable_calc(ed, ep, &dx, &dy);
2931         ep->drag->x = dx;
2932         ep->drag->y = dy;
2933         ep->drag->tmp.x = 0;
2934         ep->drag->tmp.y = 0;
2935         ep->drag->need_reset = 0;
2936      }
2937    if (!ed->calc_only)
2938      {
2939         Evas_Object *mo;
2940
2941         /* Common move, resize and color_set for all part. */
2942         switch (ep->part->type)
2943           {
2944            case EDJE_PART_TYPE_IMAGE:
2945            {
2946               Edje_Part_Description_Image *img_desc = (Edje_Part_Description_Image *)chosen_desc;
2947
2948               evas_object_image_scale_hint_set(ep->object,
2949                                                img_desc->image.scale_hint);
2950            }
2951
2952            case EDJE_PART_TYPE_PROXY:
2953            case EDJE_PART_TYPE_RECTANGLE:
2954            case EDJE_PART_TYPE_TEXTBLOCK:
2955            case EDJE_PART_TYPE_BOX:
2956            case EDJE_PART_TYPE_TABLE:
2957              evas_object_color_set(ep->object,
2958                                    (pf->color.r * pf->color.a) / 255,
2959                                    (pf->color.g * pf->color.a) / 255,
2960                                    (pf->color.b * pf->color.a) / 255,
2961                                    pf->color.a);
2962              if (!pf->visible)
2963                {
2964                   evas_object_hide(ep->object);
2965                   break;
2966                }
2967              evas_object_show(ep->object);
2968
2969            /* move and resize are needed for all previous object => no break here. */
2970            case EDJE_PART_TYPE_SWALLOW:
2971            case EDJE_PART_TYPE_GROUP:
2972            case EDJE_PART_TYPE_EXTERNAL:
2973              /* visibility and color have no meaning on SWALLOW and GROUP part. */
2974              evas_object_move(ep->object, ed->x + pf->x, ed->y + pf->y);
2975              evas_object_resize(ep->object, pf->w, pf->h);
2976              if (ep->part->entry_mode > EDJE_ENTRY_EDIT_MODE_NONE)
2977                _edje_entry_real_part_configure(ep);
2978              break;
2979
2980            case EDJE_PART_TYPE_TEXT:
2981              /* This is correctly handle in _edje_text_recalc_apply at the moment. */
2982              break;
2983
2984            case EDJE_PART_TYPE_GRADIENT:
2985              /* FIXME: definitivly remove this code when we switch to new format. */
2986              abort();
2987              break;
2988
2989            case EDJE_PART_TYPE_SPACER:
2990              /* We really should do nothing on SPACER part */
2991              break;
2992           }
2993
2994         /* Some object need special recalc. */
2995         switch (ep->part->type)
2996           {
2997            case EDJE_PART_TYPE_TEXT:
2998              _edje_text_recalc_apply(ed, ep, pf, (Edje_Part_Description_Text *)chosen_desc);
2999              break;
3000
3001            case EDJE_PART_TYPE_PROXY:
3002              _edje_proxy_recalc_apply(ed, ep, pf, (Edje_Part_Description_Proxy *)chosen_desc, pos);
3003              break;
3004
3005            case EDJE_PART_TYPE_IMAGE:
3006              _edje_image_recalc_apply(ed, ep, pf, (Edje_Part_Description_Image *)chosen_desc, pos);
3007              break;
3008
3009            case EDJE_PART_TYPE_BOX:
3010              _edje_box_recalc_apply(ed, ep, pf, (Edje_Part_Description_Box *)chosen_desc);
3011              break;
3012
3013            case EDJE_PART_TYPE_TABLE:
3014              _edje_table_recalc_apply(ed, ep, pf, (Edje_Part_Description_Table *)chosen_desc);
3015              break;
3016
3017            case EDJE_PART_TYPE_TEXTBLOCK:
3018              _edje_textblock_recalc_apply(ed, ep, pf, (Edje_Part_Description_Text *)chosen_desc);
3019              break;
3020
3021            case EDJE_PART_TYPE_EXTERNAL:
3022            case EDJE_PART_TYPE_RECTANGLE:
3023            case EDJE_PART_TYPE_SWALLOW:
3024            case EDJE_PART_TYPE_GROUP:
3025              /* Nothing special to do for this type of object. */
3026              break;
3027
3028            case EDJE_PART_TYPE_GRADIENT:
3029              /* FIXME: definitivly remove this code when we switch to new format. */
3030              abort();
3031              break;
3032
3033            case EDJE_PART_TYPE_SPACER:
3034              /* We really should do nothing on SPACER part */
3035              break;
3036           }
3037
3038         if (ep->swallowed_object)
3039           {
3040              //// the below really is wrong - swallow color shouldn't affect swallowed object
3041              //// color - the edje color as a WHOLE should though - and that should be
3042              //// done via the clipper anyway. this created bugs when objects had their
3043              //// colro set and were swallowed - then had their color changed.
3044              //      evas_object_color_set(ep->swallowed_object,
3045              //                            (pf->color.r * pf->color.a) / 255,
3046              //                            (pf->color.g * pf->color.a) / 255,
3047              //                            (pf->color.b * pf->color.a) / 255,
3048              //                            pf->color.a);
3049              if (pf->visible)
3050                {
3051                   evas_object_move(ep->swallowed_object, ed->x + pf->x, ed->y + pf->y);
3052                   evas_object_resize(ep->swallowed_object, pf->w, pf->h);
3053                   evas_object_show(ep->swallowed_object);
3054                }
3055              else evas_object_hide(ep->swallowed_object);
3056              mo = ep->swallowed_object;
3057           }
3058         else mo = ep->object;
3059         if (chosen_desc->map.on && ep->part->type != EDJE_PART_TYPE_SPACER)
3060           {
3061              static Evas_Map *map = NULL;
3062
3063              ed->have_mapped_part = 1;
3064              // create map and populate with part geometry
3065              if (!map) map = evas_map_new(4);
3066              evas_map_util_points_populate_from_object(map, ep->object);
3067              if (ep->part->type == EDJE_PART_TYPE_IMAGE ||
3068                  ((ep->part->type == EDJE_PART_TYPE_SWALLOW) &&
3069                   (!strcmp(evas_object_type_get(mo), "image") &&
3070                    (!evas_object_image_source_get(mo))))
3071                  )
3072                {
3073                   int iw = 1, ih = 1;
3074
3075                   evas_object_image_size_get(mo, &iw, &ih);
3076                   evas_map_point_image_uv_set(map, 0, 0.0, 0.0);
3077                   evas_map_point_image_uv_set(map, 1, iw, 0.0);
3078                   evas_map_point_image_uv_set(map, 2, iw, ih);
3079                   evas_map_point_image_uv_set(map, 3, 0.0, ih);
3080                }
3081              evas_map_util_3d_rotate(map,
3082                                      TO_DOUBLE(pf->map.rotation.x), TO_DOUBLE(pf->map.rotation.y), TO_DOUBLE(pf->map.rotation.z),
3083                                      pf->map.center.x, pf->map.center.y, pf->map.center.z);
3084
3085              // calculate light color & position etc. if there is one
3086              if (pf->lighted)
3087                {
3088                   evas_map_util_3d_lighting(map,
3089                                             pf->map.light.x, pf->map.light.y, pf->map.light.z,
3090                                             pf->map.light.r, pf->map.light.g, pf->map.light.b,
3091                                             pf->map.light.ar, pf->map.light.ag, pf->map.light.ab);
3092                }
3093
3094              // calculate perspective point
3095              if (chosen_desc->map.persp_on)
3096                {
3097                   evas_map_util_3d_perspective(map,
3098                                                pf->map.persp.x, pf->map.persp.y, pf->map.persp.z,
3099                                                pf->map.persp.focal);
3100                }
3101
3102              // handle backface culling (object is facing away from view
3103              if (chosen_desc->map.backcull)
3104                {
3105                   if (pf->visible)
3106                     {
3107                        if (evas_map_util_clockwise_get(map))
3108                          evas_object_show(mo);
3109                        else evas_object_hide(mo);
3110                     }
3111                }
3112
3113              // handle smooth
3114              if (chosen_desc->map.smooth) evas_map_smooth_set(map, 1);
3115              else evas_map_smooth_set(map, 0);
3116              // handle alpha
3117              if (chosen_desc->map.alpha) evas_map_alpha_set(map, 1);
3118              else evas_map_alpha_set(map, 0);
3119
3120              evas_object_map_set(mo, map);
3121              evas_object_map_enable_set(mo, 1);
3122           }
3123         else
3124           {
3125              evas_object_map_enable_set(mo, 0);
3126              evas_object_map_set(mo, NULL);
3127           }
3128      }
3129
3130    ep->x = pf->x;
3131    ep->y = pf->y;
3132    ep->w = pf->w;
3133    ep->h = pf->h;
3134
3135    ep->calculated |= flags;
3136    ep->calculating = FLAG_NONE;
3137
3138 #ifdef EDJE_CALC_CACHE
3139    if (ep->calculated == FLAG_XY)
3140      {
3141         ep->state = ed->state;
3142         ep->invalidate = 0;
3143      }
3144 #endif
3145 }
3146