TIVI-2144 : Fix Segfault during popup process creation
[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
1263                  if (minw && chosen_desc->text.min_x)
1264                     {
1265                        if (mw > *minw) *minw = mw;
1266                     }
1267                   if (minh && chosen_desc->text.min_y)
1268                     {
1269                        if (mh > *minh) *minh = mh;
1270                     }
1271                }
1272           }
1273         if ((chosen_desc->text.max_x) || (chosen_desc->text.max_y))
1274           {
1275              int mw = 0, mh = 0;
1276
1277              tw = th = 0;
1278              if (!chosen_desc->text.max_x)
1279                {
1280                   evas_object_resize(ep->object, params->w, params->h);
1281                   evas_object_textblock_size_formatted_get(ep->object, &tw, &th);
1282                }
1283              else
1284                evas_object_textblock_size_native_get(ep->object, &tw, &th);
1285              evas_object_textblock_style_insets_get(ep->object, &ins_l, &ins_r,
1286                                                     &ins_t, &ins_b);
1287              mw = ins_l + tw + ins_r;
1288              mh = ins_t + th + ins_b;
1289  
1290              if (maxw && chosen_desc->text.max_x)
1291                {
1292                   if (mw > *maxw) *maxw = mw;
1293                   if (minw && (*maxw < *minw)) *maxw = *minw;
1294                }
1295              if (maxh && chosen_desc->text.max_y)
1296                {
1297                   if (mh > *maxh) *maxh = mh;
1298                   if (minh && (*maxh < *minh)) *maxh = *minh;
1299                }
1300           }
1301         if ((chosen_desc->text.fit_x) || (chosen_desc->text.fit_y))
1302           {
1303              double s = 1.0;
1304
1305              if (ep->part->scale) s = TO_DOUBLE(sc);
1306              evas_object_scale_set(ep->object, s);
1307              evas_object_textblock_size_formatted_get(ep->object, &tw, &th);
1308              if (chosen_desc->text.fit_x)
1309                {
1310                   if ((tw > 0) && (tw > params->w))
1311                     {
1312                        s = (s * params->w) / (double)tw;
1313                        evas_object_scale_set(ep->object, s);
1314                        evas_object_textblock_size_formatted_get(ep->object,
1315                                                                 &tw, &th);
1316                     }
1317                }
1318              if (chosen_desc->text.fit_y)
1319                {
1320                   if ((th > 0) && (th > params->h))
1321                     {
1322                        s = (s * params->h) / (double)th;
1323                        evas_object_scale_set(ep->object, s);
1324                        evas_object_textblock_size_formatted_get(ep->object,
1325                                                                 &tw, &th);
1326                     }
1327                }
1328           }
1329         evas_object_textblock_valign_set(ep->object, TO_DOUBLE(chosen_desc->text.align.y));
1330      }
1331 }
1332
1333 static void
1334 _edje_textblock_recalc_apply(Edje *ed, Edje_Real_Part *ep,
1335                              Edje_Calc_Params *params,
1336                              Edje_Part_Description_Text *chosen_desc)
1337 {
1338    /* FIXME: this is just an hack. */
1339    FLOAT_T sc;
1340    sc = ed->scale;
1341    if (sc == ZERO) sc = _edje_scale;
1342    if (chosen_desc->text.fit_x || chosen_desc->text.fit_y)
1343      {
1344         _edje_part_recalc_single_textblock(sc, ed, ep, chosen_desc, params,
1345                                            NULL, NULL, NULL, NULL);
1346      }
1347 }
1348
1349 static void
1350 _edje_part_recalc_single_text(FLOAT_T sc __UNUSED__,
1351                               Edje *ed,
1352                               Edje_Real_Part *ep,
1353                               Edje_Part_Description_Text *desc,
1354                               Edje_Part_Description_Text *chosen_desc,
1355                               Edje_Calc_Params *params,
1356                               int *minw, int *minh,
1357                               int *maxw, int *maxh)
1358 #define RECALC_SINGLE_TEXT_USING_APPLY 1
1359 #if RECALC_SINGLE_TEXT_USING_APPLY
1360 /*
1361  * XXX TODO NOTE:
1362  *
1363  * Original _edje_part_recalc_single_text() was not working as
1364  * expected since it was not doing size fit, range, ellipsis and so
1365  * on.
1366  *
1367  * The purpose of this function compared with
1368  * _edje_text_recalc_apply() is to be faster, not calling Evas update
1369  * functions. However for text this is quite difficult given that to
1370  * fit we need to set the font, size, style, etc. If it was done
1371  * correctly, we'd save some calls to move and some color sets,
1372  * however those shouldn't matter much in the overall picture.
1373  *
1374  * I've changed this to force applying the value, it should be more
1375  * correct and not so slow. The previous code is kept below for
1376  * reference but should be removed before next release!
1377  *
1378  * -- Gustavo Barbieri at 20-Aug-2011
1379  */
1380 {
1381    int tw, th, mw, mh, l, r, t, b, size;
1382    char *sfont = NULL;
1383
1384    _edje_text_class_font_get(ed, desc, &size, &sfont);
1385    free(sfont);
1386    params->type.text.size = size; /* XXX TODO used by further calcs, go inside recalc_apply? */
1387
1388    _edje_text_recalc_apply(ed, ep, params, chosen_desc);
1389
1390    evas_object_geometry_get(ep->object, NULL, NULL, &tw, &th);
1391
1392    if ((!chosen_desc) ||
1393        ((!chosen_desc->text.min_x) && (!chosen_desc->text.min_y) &&
1394         (!chosen_desc->text.max_x) && (!chosen_desc->text.max_y)))
1395      return;
1396
1397    evas_object_geometry_get(ep->object, NULL, NULL, &tw, &th);
1398    evas_object_text_style_pad_get(ep->object, &l, &r, &t, &b);
1399
1400    mw = tw + l + r;
1401    mh = th + t + b;
1402
1403    if (chosen_desc->text.max_x)
1404      {
1405         if ((*maxw < 0) || (mw < *maxw)) *maxw = mw;
1406      }
1407    if (chosen_desc->text.max_y)
1408      {
1409         if ((*maxh < 0) || (mh < *maxh)) *maxh = mh;
1410      }
1411    if (chosen_desc->text.min_x)
1412      {
1413         if (mw > *minw) *minw = mw;
1414      }
1415    if (chosen_desc->text.min_y)
1416      {
1417         if (mh > *minh) *minh = mh;
1418      }
1419 }
1420
1421 #else
1422 {
1423    char *sfont = NULL;
1424    int size;
1425
1426    if (chosen_desc)
1427      {
1428         const char *text;
1429         const char *font;
1430         Evas_Coord tw, th;
1431         int inlined_font = 0;
1432
1433         /* Update a object_text part */
1434
1435         if (chosen_desc->text.id_source >= 0)
1436           ep->text.source = ed->table_parts[chosen_desc->text.id_source % ed->table_parts_size];
1437         else
1438           ep->text.source = NULL;
1439
1440         if (chosen_desc->text.id_text_source >= 0)
1441           ep->text.text_source = ed->table_parts[chosen_desc->text.id_text_source % ed->table_parts_size];
1442         else
1443           ep->text.text_source = NULL;
1444
1445         if (ep->text.text_source)
1446           text = edje_string_get(&(((Edje_Part_Description_Text *)ep->text.text_source->chosen_description)->text.text));
1447         else
1448           text = edje_string_get(&chosen_desc->text.text);
1449
1450         if (ep->text.source)
1451           font = _edje_text_class_font_get(ed, ((Edje_Part_Description_Text *)ep->text.source->chosen_description), &size, &sfont);
1452         else
1453           font = _edje_text_class_font_get(ed, chosen_desc, &size, &sfont);
1454
1455         if (!font) font = "";
1456
1457         if (ep->text.text_source)
1458           {
1459              if (ep->text.text_source->text.text) text = ep->text.text_source->text.text;
1460           }
1461         else
1462           {
1463              if (ep->text.text) text = ep->text.text;
1464           }
1465
1466         if (ep->text.source)
1467           {
1468              if (ep->text.source->text.font) font = ep->text.source->text.font;
1469              if (ep->text.source->text.size > 0) size = ep->text.source->text.size;
1470           }
1471         else
1472           {
1473              if (ep->text.font) font = ep->text.font;
1474              if (ep->text.size > 0) size = ep->text.size;
1475           }
1476         if (!text) text = "";
1477
1478         /* check if the font is embedded in the .eet */
1479         if (ed->file->fonts)
1480           {
1481              Edje_Font_Directory_Entry *fnt;
1482
1483              fnt = eina_hash_find(ed->file->fonts, font);
1484
1485              if (fnt)
1486                {
1487                   char *font2;
1488
1489                   size_t len = strlen(font) + sizeof("edje/fonts/") + 1;
1490                   font2 = alloca(len);
1491                   sprintf(font2, "edje/fonts/%s", font);
1492                   font = font2;
1493                   inlined_font = 1;
1494                }
1495           }
1496         if (ep->part->scale)
1497           evas_object_scale_set(ep->object, TO_DOUBLE(sc));
1498         if (inlined_font)
1499           {
1500              evas_object_text_font_source_set(ep->object, ed->path);
1501           }
1502         else evas_object_text_font_source_set(ep->object, NULL);
1503
1504         if ((_edje_fontset_append) && (font))
1505           {
1506              char *font2;
1507
1508              font2 = malloc(strlen(font) + 1 + strlen(_edje_fontset_append) + 1);
1509              if (font2)
1510                {
1511                   strcpy(font2, font);
1512                   strcat(font2, ",");
1513                   strcat(font2, _edje_fontset_append);
1514                   evas_object_text_font_set(ep->object, font2, size);
1515                   free(font2);
1516                }
1517           }
1518         else
1519           evas_object_text_font_set(ep->object, font, size);
1520         if ((chosen_desc->text.min_x) || (chosen_desc->text.min_y) ||
1521             (chosen_desc->text.max_x) || (chosen_desc->text.max_y))
1522           {
1523              int mw, mh;
1524              Evas_Text_Style_Type
1525                style = EVAS_TEXT_STYLE_PLAIN,
1526                shadow = EVAS_TEXT_STYLE_SHADOW_DIRECTION_BOTTOM_RIGHT;
1527              const Evas_Text_Style_Type styles[] = {
1528                 EVAS_TEXT_STYLE_PLAIN,
1529                 EVAS_TEXT_STYLE_PLAIN,
1530                 EVAS_TEXT_STYLE_OUTLINE,
1531                 EVAS_TEXT_STYLE_SOFT_OUTLINE,
1532                 EVAS_TEXT_STYLE_SHADOW,
1533                 EVAS_TEXT_STYLE_SOFT_SHADOW,
1534                 EVAS_TEXT_STYLE_OUTLINE_SHADOW,
1535                 EVAS_TEXT_STYLE_OUTLINE_SOFT_SHADOW,
1536                 EVAS_TEXT_STYLE_FAR_SHADOW,
1537                 EVAS_TEXT_STYLE_FAR_SOFT_SHADOW,
1538                 EVAS_TEXT_STYLE_GLOW
1539              };
1540              const Evas_Text_Style_Type shadows[] = {
1541                 EVAS_TEXT_STYLE_SHADOW_DIRECTION_BOTTOM_RIGHT,
1542                 EVAS_TEXT_STYLE_SHADOW_DIRECTION_BOTTOM,
1543                 EVAS_TEXT_STYLE_SHADOW_DIRECTION_BOTTOM_LEFT,
1544                 EVAS_TEXT_STYLE_SHADOW_DIRECTION_LEFT,
1545                 EVAS_TEXT_STYLE_SHADOW_DIRECTION_TOP_LEFT,
1546                 EVAS_TEXT_STYLE_SHADOW_DIRECTION_TOP,
1547                 EVAS_TEXT_STYLE_SHADOW_DIRECTION_TOP_RIGHT,
1548                 EVAS_TEXT_STYLE_SHADOW_DIRECTION_RIGHT
1549              };
1550
1551              if ((ep->part->effect & EVAS_TEXT_STYLE_MASK_BASIC)
1552                  < EDJE_TEXT_EFFECT_LAST)
1553                style = styles[ep->part->effect];
1554              shadow = shadows
1555                [(ep->part->effect & EDJE_TEXT_EFFECT_MASK_SHADOW_DIRECTION) >> 4];
1556              EVAS_TEXT_STYLE_SHADOW_DIRECTION_SET(style, shadow);
1557
1558              evas_object_text_style_set(ep->object, style);
1559              evas_object_text_text_set(ep->object, text);
1560              evas_object_geometry_get(ep->object, NULL, NULL, &tw, &th);
1561              if (chosen_desc->text.max_x)
1562                {
1563                   int l, r;
1564                   evas_object_text_style_pad_get(ep->object, &l, &r, NULL, NULL);
1565                   mw = tw + l + r;
1566                   if ((*maxw < 0) || (mw < *maxw)) *maxw = mw;
1567                }
1568              if (chosen_desc->text.max_y)
1569                {
1570                   int t, b;
1571                   evas_object_text_style_pad_get(ep->object, NULL, NULL, &t, &b);
1572                   mh = th + t + b;
1573                   if ((*maxh < 0) || (mh < *maxh)) *maxh = mh;
1574                }
1575              if (chosen_desc->text.min_x)
1576                {
1577                   int l, r;
1578                   evas_object_text_style_pad_get(ep->object, &l, &r, NULL, NULL);
1579                   mw = tw + l + r;
1580                   if (mw > *minw) *minw = mw;
1581                }
1582              if (chosen_desc->text.min_y)
1583                {
1584                   int t, b;
1585                   evas_object_text_style_pad_get(ep->object, NULL, NULL, &t, &b);
1586                   mh = th + t + b;
1587                   if (mh > *minh) *minh = mh;
1588                }
1589           }
1590         if (sfont) free(sfont);
1591      }
1592
1593    /* FIXME: Do we really need to call it twice if chosen_desc ? */
1594    sfont = NULL;
1595    _edje_text_class_font_get(ed, desc, &size, &sfont);
1596    free(sfont);
1597    params->type.text.size = size;
1598 }
1599 #endif
1600
1601 static void
1602 _edje_part_recalc_single_min_length(FLOAT_T align, int *start, int *length, int min)
1603 {
1604    if (min >= 0)
1605      {
1606         if (*length < min)
1607           {
1608              *start += TO_INT(SCALE(align, (*length - min)));
1609              *length = min;
1610           }
1611      }
1612 }
1613
1614 static void
1615 _edje_part_recalc_single_min(Edje_Part_Description_Common *desc,
1616                              Edje_Calc_Params *params,
1617                              int minw, int minh,
1618                              Edje_Internal_Aspect aspect)
1619 {
1620    int tmp;
1621    int w;
1622    int h;
1623
1624    w = params->w ? params->w : 99999;
1625    h = params->h ? params->h : 99999;
1626
1627    switch (aspect)
1628      {
1629       case EDJE_ASPECT_PREFER_NONE:
1630         break;
1631
1632       case EDJE_ASPECT_PREFER_VERTICAL:
1633         tmp = minh * params->w / h;
1634         if (tmp >= minw)
1635           {
1636              minw = tmp;
1637              break;
1638           }
1639
1640       case EDJE_ASPECT_PREFER_HORIZONTAL:
1641         tmp = minw * params->h / w;
1642         if (tmp >= minh)
1643           {
1644              minh = tmp;
1645              break;
1646           }
1647
1648       case EDJE_ASPECT_PREFER_SOURCE:
1649       case EDJE_ASPECT_PREFER_BOTH:
1650         tmp = minh * params->w / h;
1651         if (tmp >= minw)
1652           {
1653              minw = tmp;
1654              break;
1655           }
1656
1657         tmp = minw * params->h / w;
1658         if (tmp >= minh)
1659           {
1660              minh = tmp;
1661              break;
1662           }
1663
1664         break;
1665      }
1666
1667    _edje_part_recalc_single_min_length(desc->align.x, &params->x, &params->w, minw);
1668    _edje_part_recalc_single_min_length(desc->align.y, &params->y, &params->h, minh);
1669 }
1670
1671 static void
1672 _edje_part_recalc_single_max_length(FLOAT_T align, int *start, int *length, int max)
1673 {
1674    if (max >= 0)
1675      {
1676         if (*length > max)
1677           {
1678              *start += TO_INT(SCALE(align, (*length - max)));
1679              *length = max;
1680           }
1681      }
1682 }
1683
1684 static void
1685 _edje_part_recalc_single_max(Edje_Part_Description_Common *desc,
1686                              Edje_Calc_Params *params,
1687                              int maxw, int maxh,
1688                              Edje_Internal_Aspect aspect)
1689 {
1690    int tmp;
1691    int w;
1692    int h;
1693
1694    w = params->w ? params->w : 99999;
1695    h = params->h ? params->h : 99999;
1696
1697    switch (aspect)
1698      {
1699       case EDJE_ASPECT_PREFER_NONE:
1700         break;
1701
1702       case EDJE_ASPECT_PREFER_VERTICAL:
1703         tmp = maxh * params->w / h;
1704         if (tmp <= maxw)
1705           {
1706              maxw = tmp;
1707              break;
1708           }
1709
1710       case EDJE_ASPECT_PREFER_HORIZONTAL:
1711         tmp = maxw * params->h / w;
1712         if (tmp <= maxh)
1713           {
1714              maxh = tmp;
1715              break;
1716           }
1717
1718       case EDJE_ASPECT_PREFER_SOURCE:
1719       case EDJE_ASPECT_PREFER_BOTH:
1720         tmp = maxh * params->w / h;
1721         if (tmp <= maxw)
1722           {
1723              maxw = tmp;
1724              break;
1725           }
1726
1727         tmp = maxw * params->h / w;
1728         if (tmp <= maxh)
1729           {
1730              maxh = tmp;
1731              break;
1732           }
1733
1734         break;
1735      }
1736
1737    _edje_part_recalc_single_max_length(desc->align.x, &params->x, &params->w, maxw);
1738    _edje_part_recalc_single_max_length(desc->align.y, &params->y, &params->h, maxh);
1739 }
1740
1741 static void
1742 _edje_part_recalc_single_drag(Edje_Real_Part *ep,
1743                               Edje_Real_Part *confine_to,
1744                               Edje_Calc_Params *params,
1745                               int minw, int minh,
1746                               int maxw, int maxh)
1747 {
1748    /* confine */
1749    if (confine_to)
1750      {
1751         int offset;
1752         int step;
1753         FLOAT_T v;
1754
1755         /* complex dragable params */
1756         v = SCALE(ep->drag->size.x, confine_to->w);
1757
1758         if ((minw > 0) && (TO_INT(v) < minw)) params->w = minw;
1759         else if ((maxw >= 0) && (TO_INT(v) > maxw))
1760           params->w = maxw;
1761         else params->w = TO_INT(v);
1762
1763         offset = TO_INT(SCALE(ep->drag->x, (confine_to->w - params->w)))
1764           + ep->drag->tmp.x;
1765         if (ep->part->dragable.step_x > 0)
1766           {
1767              params->x = confine_to->x +
1768                ((offset / ep->part->dragable.step_x) * ep->part->dragable.step_x);
1769           }
1770         else if (ep->part->dragable.count_x > 0)
1771           {
1772              step = (confine_to->w - params->w) / ep->part->dragable.count_x;
1773              if (step < 1) step = 1;
1774              params->x = confine_to->x +
1775                ((offset / step) * step);
1776           }
1777         params->req_drag.x = params->x;
1778         params->req_drag.w = params->w;
1779
1780         v = SCALE(ep->drag->size.y, confine_to->h);
1781
1782         if ((minh > 0) && (TO_INT(v) < minh)) params->h = minh;
1783         else if ((maxh >= 0) && (TO_INT(v) > maxh))
1784           params->h = maxh;
1785         else params->h = TO_INT(v);
1786
1787         offset = TO_INT(SCALE(ep->drag->y, (confine_to->h - params->h)))
1788           + ep->drag->tmp.y;
1789         if (ep->part->dragable.step_y > 0)
1790           {
1791              params->y = confine_to->y +
1792                ((offset / ep->part->dragable.step_y) * ep->part->dragable.step_y);
1793           }
1794         else if (ep->part->dragable.count_y > 0)
1795           {
1796              step = (confine_to->h - params->h) / ep->part->dragable.count_y;
1797              if (step < 1) step = 1;
1798              params->y = confine_to->y +
1799                ((offset / step) * step);
1800           }
1801         params->req_drag.y = params->y;
1802         params->req_drag.h = params->h;
1803
1804         /* limit to confine */
1805         if (params->x < confine_to->x)
1806           {
1807              params->x = confine_to->x;
1808           }
1809         if ((params->x + params->w) > (confine_to->x + confine_to->w))
1810           {
1811              params->x = confine_to->x + confine_to->w - params->w;
1812           }
1813         if (params->y < confine_to->y)
1814           {
1815              params->y = confine_to->y;
1816           }
1817         if ((params->y + params->h) > (confine_to->y + confine_to->h))
1818           {
1819              params->y = confine_to->y + confine_to->h - params->h;
1820           }
1821      }
1822    else
1823      {
1824         /* simple dragable params */
1825         params->x += TO_INT(ep->drag->x) + ep->drag->tmp.x;
1826         params->req_drag.x = params->x;
1827         params->req_drag.w = params->w;
1828
1829         params->y += TO_INT(ep->drag->y) + ep->drag->tmp.y;
1830         params->req_drag.y = params->y;
1831         params->req_drag.h = params->h;
1832      }
1833 }
1834
1835 static void
1836 _edje_part_recalc_single_fill(Edje_Real_Part *ep,
1837                               Edje_Part_Description_Spec_Fill *fill,
1838                               Edje_Calc_Params *params)
1839 {
1840    int fw;
1841    int fh;
1842
1843    params->smooth = fill->smooth;
1844
1845    if (fill->type == EDJE_FILL_TYPE_TILE)
1846      evas_object_image_size_get(ep->object, &fw, NULL);
1847    else
1848      fw = params->w;
1849
1850    params->type.common.fill.x = fill->pos_abs_x
1851      + TO_INT(SCALE(fill->pos_rel_x, fw));
1852    params->type.common.fill.w = fill->abs_x
1853      + TO_INT(SCALE(fill->rel_x, fw));
1854
1855    if (fill->type == EDJE_FILL_TYPE_TILE)
1856      evas_object_image_size_get(ep->object, NULL, &fh);
1857    else
1858      fh = params->h;
1859
1860    params->type.common.fill.y = fill->pos_abs_y
1861      + TO_INT(SCALE(fill->pos_rel_y, fh));
1862    params->type.common.fill.h = fill->abs_y
1863      + TO_INT(SCALE(fill->rel_y, fh));
1864
1865    params->type.common.fill.angle = fill->angle;
1866    params->type.common.fill.spread = fill->spread;
1867 }
1868
1869 static void
1870 _edje_part_recalc_single_min_max(FLOAT_T sc,
1871                                  Edje_Real_Part *ep,
1872                                  Edje_Part_Description_Common *desc,
1873                                  int *minw, int *minh,
1874                                  int *maxw, int *maxh)
1875 {
1876    *minw = desc->min.w;
1877    if (ep->part->scale) *minw = TO_INT(SCALE(sc, *minw));
1878    if (ep->swallow_params.min.w > desc->min.w)
1879      *minw = ep->swallow_params.min.w;
1880
1881    if (ep->edje->calc_only)
1882      {
1883         if (desc->minmul.have)
1884           {
1885              FLOAT_T mmw = desc->minmul.w;
1886              if (mmw != FROM_INT(1)) *minw = TO_INT(SCALE(mmw, *minw));
1887           }
1888      }
1889
1890    /* XXX TODO: remove need of EDJE_INF_MAX_W, see edje_util.c */
1891    if ((ep->swallow_params.max.w <= 0) ||
1892        (ep->swallow_params.max.w == EDJE_INF_MAX_W))
1893      {
1894         *maxw = desc->max.w;
1895         if (*maxw > 0)
1896           {
1897              if (ep->part->scale) *maxw = TO_INT(SCALE(sc, *maxw));
1898              if (*maxw < 1) *maxw = 1;
1899           }
1900      }
1901    else
1902      {
1903         if (desc->max.w <= 0)
1904           *maxw = ep->swallow_params.max.w;
1905         else
1906           {
1907              *maxw = desc->max.w;
1908              if (*maxw > 0)
1909                {
1910                   if (ep->part->scale) *maxw = TO_INT(SCALE(sc, *maxw));
1911                   if (*maxw < 1) *maxw = 1;
1912                }
1913              if (ep->swallow_params.max.w < *maxw)
1914                *maxw = ep->swallow_params.max.w;
1915           }
1916      }
1917    if ((ep->edje->calc_only) && (desc->minmul.have) &&
1918        (desc->minmul.w != FROM_INT(1))) *maxw = *minw;
1919    if (*maxw >= 0)
1920      {
1921         if (*maxw < *minw) *maxw = *minw;
1922      }
1923
1924    *minh = desc->min.h;
1925    if (ep->part->scale) *minh = TO_INT(SCALE(sc, *minh));
1926    if (ep->swallow_params.min.h > desc->min.h)
1927      *minh = ep->swallow_params.min.h;
1928
1929    if (ep->edje->calc_only)
1930      {
1931         if (desc->minmul.have)
1932           {
1933              FLOAT_T mmh = desc->minmul.h;
1934              if (mmh != FROM_INT(1)) *minh = TO_INT(SCALE(mmh, *minh));
1935           }
1936      }
1937
1938    /* XXX TODO: remove need of EDJE_INF_MAX_H, see edje_util.c */
1939    if ((ep->swallow_params.max.h <= 0) ||
1940        (ep->swallow_params.max.h == EDJE_INF_MAX_H))
1941      {
1942         *maxh = desc->max.h;
1943         if (*maxh > 0)
1944           {
1945              if (ep->part->scale) *maxh = TO_INT(SCALE(sc, *maxh));
1946              if (*maxh < 1) *maxh = 1;
1947           }
1948      }
1949    else
1950      {
1951         if (desc->max.h <= 0)
1952           *maxh = ep->swallow_params.max.h;
1953         else
1954           {
1955              *maxh = desc->max.h;
1956              if (*maxh > 0)
1957                {
1958                   if (ep->part->scale) *maxh = TO_INT(SCALE(sc, *maxh));
1959                   if (*maxh < 1) *maxh = 1;
1960                }
1961              if (ep->swallow_params.max.h < *maxh)
1962                *maxh = ep->swallow_params.max.h;
1963           }
1964      }
1965    if ((ep->edje->calc_only) && (desc->minmul.have) &&
1966        (desc->minmul.h != FROM_INT(1))) *maxh = *minh;
1967    if (*maxh >= 0)
1968      {
1969         if (*maxh < *minh) *maxh = *minh;
1970      }
1971 }
1972
1973 static void
1974 _edje_part_recalc_single_map(Edje *ed,
1975                              Edje_Real_Part *ep __UNUSED__,
1976                              Edje_Real_Part *center,
1977                              Edje_Real_Part *light,
1978                              Edje_Real_Part *persp,
1979                              Edje_Part_Description_Common *desc,
1980                              Edje_Part_Description_Common *chosen_desc,
1981                              Edje_Calc_Params *params)
1982 {
1983    params->mapped = chosen_desc->map.on;
1984    params->lighted = params->mapped ? !!light : 0;
1985    params->persp_on = params->mapped ? !!persp : 0;
1986
1987    if (!params->mapped) return;
1988
1989    if (center)
1990      {
1991         params->map.center.x = ed->x + center->x + (center->w / 2);
1992         params->map.center.y = ed->y + center->y + (center->h / 2);
1993      }
1994    else
1995      {
1996         params->map.center.x = ed->x + params->x + (params->w / 2);
1997         params->map.center.y = ed->y + params->y + (params->h / 2);
1998      }
1999    params->map.center.z = 0;
2000
2001    params->map.rotation.x = desc->map.rot.x;
2002    params->map.rotation.y = desc->map.rot.y;
2003    params->map.rotation.z = desc->map.rot.z;
2004
2005    if (light)
2006      {
2007         Edje_Part_Description_Common *light_desc2;
2008         FLOAT_T pos, pos2;
2009
2010         params->map.light.x = ed->x + light->x + (light->w / 2);
2011         params->map.light.y = ed->y + light->y + (light->h / 2);
2012
2013         pos = light->description_pos;
2014         pos2 = (pos < ZERO) ? ZERO : ((pos > FROM_INT(1)) ? FROM_INT(1) : pos);
2015
2016         light_desc2 = light->param2 ? light->param2->description : NULL;
2017
2018         /* take into account CURRENT state also */
2019         if (pos != ZERO && light_desc2)
2020           {
2021              params->map.light.z = light->param1.description->persp.zplane +
2022                TO_INT(SCALE(pos, light_desc2->persp.zplane - light->param1.description->persp.zplane));
2023              params->map.light.r = light->param1.description->color.r +
2024                TO_INT(SCALE(pos2, light_desc2->color.r - light->param1.description->color.r));
2025              params->map.light.g = light->param1.description->color.g +
2026                TO_INT(SCALE(pos2, light_desc2->color.g - light->param1.description->color.g));
2027              params->map.light.b = light->param1.description->color.b +
2028                TO_INT(SCALE(pos2, light_desc2->color.b - light->param1.description->color.b));
2029              params->map.light.ar = light->param1.description->color2.r +
2030                TO_INT(SCALE(pos2, light_desc2->color2.r - light->param1.description->color2.r));
2031              params->map.light.ag = light->param1.description->color2.g +
2032                TO_INT(SCALE(pos2, light_desc2->color2.g - light->param1.description->color2.g));
2033              params->map.light.ab = light->param1.description->color2.b +
2034                TO_INT(SCALE(pos2, light_desc2->color2.b - light->param1.description->color2.b));
2035           }
2036         else
2037           {
2038              params->map.light.z = light->param1.description->persp.zplane;
2039              params->map.light.r = light->param1.description->color.r;
2040              params->map.light.g = light->param1.description->color.g;
2041              params->map.light.b = light->param1.description->color.b;
2042              params->map.light.ar = light->param1.description->color2.r;
2043              params->map.light.ag = light->param1.description->color2.g;
2044              params->map.light.ab = light->param1.description->color2.b;
2045           }
2046      }
2047
2048    if (persp)
2049      {
2050         FLOAT_T pos;
2051
2052         params->map.persp.x = ed->x + persp->x + (persp->w / 2);
2053         params->map.persp.y = ed->y + persp->y + (persp->h / 2);
2054
2055         pos = persp->description_pos;
2056
2057         if (pos != 0 && persp->param2)
2058           {
2059              params->map.persp.z = persp->param1.description->persp.zplane +
2060                TO_INT(SCALE(pos, persp->param2->description->persp.zplane -
2061                             persp->param1.description->persp.zplane));
2062              params->map.persp.focal = persp->param1.description->persp.focal +
2063                TO_INT(SCALE(pos, persp->param2->description->persp.focal -
2064                             persp->param1.description->persp.focal));
2065           }
2066         else
2067           {
2068              params->map.persp.z = persp->param1.description->persp.zplane;
2069              params->map.persp.focal = persp->param1.description->persp.focal;
2070           }
2071      }
2072 }
2073
2074 static void
2075 _edje_part_recalc_single(Edje *ed,
2076                          Edje_Real_Part *ep,
2077                          Edje_Part_Description_Common *desc,
2078                          Edje_Part_Description_Common *chosen_desc,
2079                          Edje_Real_Part *center,
2080                          Edje_Real_Part *light,
2081                          Edje_Real_Part *persp,
2082                          Edje_Real_Part *rel1_to_x,
2083                          Edje_Real_Part *rel1_to_y,
2084                          Edje_Real_Part *rel2_to_x,
2085                          Edje_Real_Part *rel2_to_y,
2086                          Edje_Real_Part *confine_to,
2087                          Edje_Calc_Params *params,
2088                          FLOAT_T pos)
2089 {
2090    Edje_Color_Class *cc = NULL;
2091    Edje_Internal_Aspect apref;
2092    int minw = 0, minh = 0, maxw = 0, maxh = 0;
2093    FLOAT_T sc;
2094
2095    sc = ed->scale;
2096    if (sc == ZERO) sc = _edje_scale;
2097    _edje_part_recalc_single_min_max(sc, ep, desc, &minw, &minh, &maxw, &maxh);
2098
2099    /* relative coords of top left & bottom right */
2100    _edje_part_recalc_single_rel(ed, ep, desc, rel1_to_x, rel1_to_y, rel2_to_x, rel2_to_y, params);
2101
2102    /* aspect */
2103    apref = _edje_part_recalc_single_aspect(ed, ep, desc, params, &minw, &minh, &maxw, &maxh, pos);
2104
2105    /* size step */
2106    _edje_part_recalc_single_step(desc, params);
2107
2108    /* if we have text that wants to make the min size the text size... */
2109    if (ep->part->type == EDJE_PART_TYPE_TEXTBLOCK)
2110      _edje_part_recalc_single_textblock(sc, ed, ep, (Edje_Part_Description_Text *)chosen_desc, params, &minw, &minh, &maxw, &maxh);
2111    else if (ep->part->type == EDJE_PART_TYPE_TEXT)
2112      _edje_part_recalc_single_text(sc, ed, ep, (Edje_Part_Description_Text *)desc, (Edje_Part_Description_Text *)chosen_desc, params, &minw, &minh, &maxw, &maxh);
2113
2114    if ((ep->part->type == EDJE_PART_TYPE_TABLE) &&
2115        (((((Edje_Part_Description_Table *)chosen_desc)->table.min.h) ||
2116          (((Edje_Part_Description_Table *)chosen_desc)->table.min.v))))
2117      {
2118         Evas_Coord lminw = 0, lminh = 0;
2119
2120         evas_object_smart_need_recalculate_set(ep->object, 1);
2121         evas_object_smart_calculate(ep->object);
2122         evas_object_size_hint_min_get(ep->object, &lminw, &lminh);
2123         if (((Edje_Part_Description_Table *)chosen_desc)->table.min.h)
2124           {
2125              if (lminw > minw) minw = lminw;
2126           }
2127         if (((Edje_Part_Description_Table *)chosen_desc)->table.min.v)
2128           {
2129              if (lminh > minh) minh = lminh;
2130           }
2131      }
2132    else if ((ep->part->type == EDJE_PART_TYPE_BOX) &&
2133             ((((Edje_Part_Description_Box *)chosen_desc)->box.min.h) ||
2134              (((Edje_Part_Description_Box *)chosen_desc)->box.min.v)))
2135      {
2136         Evas_Coord lminw = 0, lminh = 0;
2137
2138         evas_object_smart_need_recalculate_set(ep->object, 1);
2139         evas_object_smart_calculate(ep->object);
2140         evas_object_size_hint_min_get(ep->object, &lminw, &lminh);
2141         if (((Edje_Part_Description_Box *)chosen_desc)->box.min.h)
2142           {
2143              if (lminw > minw) minw = lminw;
2144           }
2145         if (((Edje_Part_Description_Box *)chosen_desc)->box.min.v)
2146           {
2147              if (lminh > minh) minh = lminh;
2148           }
2149      }
2150    else if ((ep->part->type == EDJE_PART_TYPE_IMAGE) &&
2151             (chosen_desc->min.limit || chosen_desc->max.limit))
2152      {
2153         Evas_Coord w, h;
2154
2155         /* We only need pos to find the right image that would be displayed */
2156         /* Yes, if someone set aspect preference to SOURCE and also max,min
2157            to SOURCE, it will be under efficient, but who cares at the
2158            moment. */
2159         _edje_real_part_image_set(ed, ep, pos);
2160         evas_object_image_size_get(ep->object, &w, &h);
2161
2162         if (chosen_desc->min.limit)
2163           {
2164              if (w > minw) minw = w;
2165              if (h > minh) minh = h;
2166           }
2167         if (chosen_desc->max.limit)
2168           {
2169              if ((maxw <= 0) || (w < maxw)) maxw = w;
2170              if ((maxh <= 0) || (h < maxh)) maxh = h;
2171           }
2172      }
2173
2174    /* remember what our size is BEFORE we go limit it */
2175    params->req.x = params->x;
2176    params->req.y = params->y;
2177    params->req.w = params->w;
2178    params->req.h = params->h;
2179
2180    /* adjust for min size */
2181    _edje_part_recalc_single_min(desc, params, minw, minh, apref);
2182
2183    /* adjust for max size */
2184    _edje_part_recalc_single_max(desc, params, maxw, maxh, apref);
2185
2186    /* take care of dragable part */
2187    if (ep->drag)
2188      _edje_part_recalc_single_drag(ep, confine_to, params, minw, minh, maxw, maxh);
2189
2190    /* fill */
2191    if (ep->part->type == EDJE_PART_TYPE_IMAGE)
2192      _edje_part_recalc_single_fill(ep, &((Edje_Part_Description_Image *)desc)->image.fill, params);
2193    else if (ep->part->type == EDJE_PART_TYPE_PROXY)
2194      _edje_part_recalc_single_fill(ep, &((Edje_Part_Description_Proxy *)desc)->proxy.fill, params);
2195
2196    if (ep->part->type != EDJE_PART_TYPE_SPACER)
2197      {
2198         /* colors */
2199         if ((desc->color_class) && (*desc->color_class))
2200           cc = _edje_color_class_find(ed, desc->color_class);
2201
2202         if (cc)
2203           {
2204              params->color.r = (((int)cc->r + 1) * desc->color.r) >> 8;
2205              params->color.g = (((int)cc->g + 1) * desc->color.g) >> 8;
2206              params->color.b = (((int)cc->b + 1) * desc->color.b) >> 8;
2207              params->color.a = (((int)cc->a + 1) * desc->color.a) >> 8;
2208           }
2209         else
2210           {
2211              params->color.r = desc->color.r;
2212              params->color.g = desc->color.g;
2213              params->color.b = desc->color.b;
2214              params->color.a = desc->color.a;
2215           }
2216      }
2217
2218    /* visible */
2219    params->visible = desc->visible;
2220
2221    switch (ep->part->type)
2222      {
2223       case EDJE_PART_TYPE_IMAGE:
2224       {
2225          Edje_Part_Description_Image *img_desc = (Edje_Part_Description_Image *)desc;
2226
2227          /* border */
2228          params->type.common.spec.image.l = img_desc->image.border.l;
2229          params->type.common.spec.image.r = img_desc->image.border.r;
2230
2231          params->type.common.spec.image.t = img_desc->image.border.t;
2232          params->type.common.spec.image.b = img_desc->image.border.b;
2233
2234          params->type.common.spec.image.border_scale_by = img_desc->image.border.scale_by;
2235          break;
2236       }
2237
2238       case EDJE_PART_TYPE_TEXT:
2239       case EDJE_PART_TYPE_TEXTBLOCK:
2240       {
2241          Edje_Part_Description_Text *text_desc = (Edje_Part_Description_Text *)desc;
2242
2243          /* text.align */
2244          params->type.text.align.x = text_desc->text.align.x;
2245          params->type.text.align.y = text_desc->text.align.y;
2246          params->type.text.elipsis = text_desc->text.elipsis;
2247
2248          /* text colors */
2249          if (cc)
2250            {
2251               params->type.text.color2.r = (((int)cc->r2 + 1) * text_desc->common.color2.r) >> 8;
2252               params->type.text.color2.g = (((int)cc->g2 + 1) * text_desc->common.color2.g) >> 8;
2253               params->type.text.color2.b = (((int)cc->b2 + 1) * text_desc->common.color2.b) >> 8;
2254               params->type.text.color2.a = (((int)cc->a2 + 1) * text_desc->common.color2.a) >> 8;
2255               params->type.text.color3.r = (((int)cc->r3 + 1) * text_desc->text.color3.r) >> 8;
2256               params->type.text.color3.g = (((int)cc->g3 + 1) * text_desc->text.color3.g) >> 8;
2257               params->type.text.color3.b = (((int)cc->b3 + 1) * text_desc->text.color3.b) >> 8;
2258               params->type.text.color3.a = (((int)cc->a3 + 1) * text_desc->text.color3.a) >> 8;
2259            }
2260          else
2261            {
2262               params->type.text.color2.r = text_desc->common.color2.r;
2263               params->type.text.color2.g = text_desc->common.color2.g;
2264               params->type.text.color2.b = text_desc->common.color2.b;
2265               params->type.text.color2.a = text_desc->common.color2.a;
2266               params->type.text.color3.r = text_desc->text.color3.r;
2267               params->type.text.color3.g = text_desc->text.color3.g;
2268               params->type.text.color3.b = text_desc->text.color3.b;
2269               params->type.text.color3.a = text_desc->text.color3.a;
2270            }
2271
2272          break;
2273       }
2274
2275       case EDJE_PART_TYPE_SPACER:
2276       case EDJE_PART_TYPE_RECTANGLE:
2277       case EDJE_PART_TYPE_BOX:
2278       case EDJE_PART_TYPE_TABLE:
2279       case EDJE_PART_TYPE_SWALLOW:
2280       case EDJE_PART_TYPE_GROUP:
2281       case EDJE_PART_TYPE_PROXY:
2282         break;
2283
2284       case EDJE_PART_TYPE_GRADIENT:
2285         /* FIXME: THIS ONE SHOULD NEVER BE TRIGGERED. */
2286         break;
2287
2288       default:
2289         break;
2290      }
2291
2292    _edje_part_recalc_single_map(ed, ep, center, light, persp, desc, chosen_desc, params);
2293 }
2294
2295 static void
2296 _edje_table_recalc_apply(Edje *ed __UNUSED__,
2297                          Edje_Real_Part *ep,
2298                          Edje_Calc_Params *p3 __UNUSED__,
2299                          Edje_Part_Description_Table *chosen_desc)
2300 {
2301    evas_object_table_homogeneous_set(ep->object, chosen_desc->table.homogeneous);
2302    evas_object_table_align_set(ep->object, TO_DOUBLE(chosen_desc->table.align.x), TO_DOUBLE(chosen_desc->table.align.y));
2303    evas_object_table_padding_set(ep->object, chosen_desc->table.padding.x, chosen_desc->table.padding.y);
2304    if (evas_object_smart_need_recalculate_get(ep->object))
2305      {
2306         evas_object_smart_need_recalculate_set(ep->object, 0);
2307         evas_object_smart_calculate(ep->object);
2308      }
2309 }
2310
2311 static void
2312 _edje_proxy_recalc_apply(Edje *ed, Edje_Real_Part *ep, Edje_Calc_Params *p3, Edje_Part_Description_Proxy *chosen_desc, FLOAT_T pos)
2313 {
2314    Edje_Real_Part *pp;
2315    int part_id = -1;
2316
2317    if (pos >= FROM_DOUBLE(0.5))
2318      part_id = ((Edje_Part_Description_Proxy *)ep->param2->description)->proxy.id;
2319    else
2320      part_id = chosen_desc->proxy.id;
2321
2322    if ((p3->type.common.fill.w == 0) || (p3->type.common.fill.h == 0) ||
2323        (part_id < 0))
2324      {
2325         evas_object_image_source_set(ep->object, NULL);
2326         return;
2327      }
2328    pp = ed->table_parts[part_id % ed->table_parts_size];
2329
2330    switch (pp->part->type)
2331      {
2332       case EDJE_PART_TYPE_IMAGE:
2333       case EDJE_PART_TYPE_TEXT:
2334       case EDJE_PART_TYPE_TEXTBLOCK:
2335       case EDJE_PART_TYPE_RECTANGLE:
2336       case EDJE_PART_TYPE_BOX:
2337       case EDJE_PART_TYPE_TABLE:
2338       case EDJE_PART_TYPE_PROXY:
2339         evas_object_image_source_set(ep->object, pp->object);
2340         break;
2341
2342       case EDJE_PART_TYPE_GRADIENT:
2343         /* FIXME: THIS ONE SHOULD NEVER BE TRIGGERED. */
2344         break;
2345
2346       case EDJE_PART_TYPE_GROUP:
2347       case EDJE_PART_TYPE_SWALLOW:
2348       case EDJE_PART_TYPE_EXTERNAL:
2349         evas_object_image_source_set(ep->object, pp->swallowed_object);
2350         break;
2351
2352       case EDJE_PART_TYPE_SPACER:
2353         /* FIXME: detect that at compile time and prevent it */
2354         break;
2355      }
2356
2357    evas_object_image_fill_set(ep->object, p3->type.common.fill.x, p3->type.common.fill.y,
2358                               p3->type.common.fill.w, p3->type.common.fill.h);
2359    evas_object_image_smooth_scale_set(ep->object, p3->smooth);
2360 }
2361
2362 static void
2363 _edje_image_recalc_apply(Edje *ed, Edje_Real_Part *ep, Edje_Calc_Params *p3, Edje_Part_Description_Image *chosen_desc, FLOAT_T pos)
2364 {
2365    FLOAT_T sc;
2366
2367    sc = ed->scale;
2368    if (sc == 0.0) sc = _edje_scale;
2369    evas_object_image_fill_set(ep->object, p3->type.common.fill.x, p3->type.common.fill.y,
2370                               p3->type.common.fill.w, p3->type.common.fill.h);
2371    evas_object_image_smooth_scale_set(ep->object, p3->smooth);
2372    if (chosen_desc->image.border.scale)
2373      {
2374         if (p3->type.common.spec.image.border_scale_by > FROM_DOUBLE(0.0))
2375           {
2376              FLOAT_T sc2 = MUL(sc, p3->type.common.spec.image.border_scale_by);
2377              evas_object_image_border_scale_set(ep->object, TO_DOUBLE(sc2));
2378           }
2379         else
2380           evas_object_image_border_scale_set(ep->object, TO_DOUBLE(sc));
2381      }
2382    else
2383      {
2384         if (p3->type.common.spec.image.border_scale_by > FROM_DOUBLE(0.0))
2385           evas_object_image_border_scale_set
2386             (ep->object, TO_DOUBLE(p3->type.common.spec.image.border_scale_by));
2387         else
2388           evas_object_image_border_scale_set(ep->object, 1.0);
2389      }
2390    evas_object_image_border_set(ep->object, p3->type.common.spec.image.l, p3->type.common.spec.image.r,
2391                                 p3->type.common.spec.image.t, p3->type.common.spec.image.b);
2392    if (chosen_desc->image.border.no_fill == 0)
2393      evas_object_image_border_center_fill_set(ep->object, EVAS_BORDER_FILL_DEFAULT);
2394    else if (chosen_desc->image.border.no_fill == 1)
2395      evas_object_image_border_center_fill_set(ep->object, EVAS_BORDER_FILL_NONE);
2396    else if (chosen_desc->image.border.no_fill == 2)
2397      evas_object_image_border_center_fill_set(ep->object, EVAS_BORDER_FILL_SOLID);
2398
2399    _edje_real_part_image_set(ed, ep, pos);
2400 }
2401
2402 static Edje_Real_Part *
2403 _edje_real_part_state_get(Edje *ed, Edje_Real_Part *ep, int flags, int id, int *state)
2404 {
2405    Edje_Real_Part *result = NULL;
2406
2407    if (id >= 0 && id != ep->part->id)
2408      {
2409         result = ed->table_parts[id % ed->table_parts_size];
2410         if (result)
2411           {
2412              if (!result->calculated) _edje_part_recalc(ed, result, flags, NULL);
2413 #ifdef EDJE_CALC_CACHE
2414              if (state) *state = result->state;
2415 #else
2416              (void)state;
2417 #endif
2418           }
2419      }
2420    return result;
2421 }
2422
2423 void
2424 _edje_part_recalc(Edje *ed, Edje_Real_Part *ep, int flags, Edje_Calc_Params *state)
2425 {
2426 #ifdef EDJE_CALC_CACHE
2427    Eina_Bool proxy_invalidate = EINA_FALSE;
2428    int state1 = -1;
2429    int state2 = -1;
2430    int statec = -1;
2431 #else
2432    Edje_Calc_Params lp1, lp2;
2433 #endif
2434    int statec1 = -1;
2435    int statec2 = -1;
2436    int statel1 = -1;
2437    int statel2 = -1;
2438    int statep1 = -1;
2439    int statep2 = -1;
2440    Edje_Real_Part *center[2] = { NULL, NULL };
2441    Edje_Real_Part *light[2] = { NULL, NULL };
2442    Edje_Real_Part *persp[2] = { NULL, NULL };
2443    Edje_Calc_Params *p1, *pf;
2444    Edje_Part_Description_Common *chosen_desc;
2445    Edje_Real_Part *confine_to = NULL;
2446    FLOAT_T pos = ZERO, pos2;
2447    Edje_Calc_Params lp3;
2448
2449    /* GRADIENT ARE GONE, WE MUST IGNORE IT FROM OLD FILE. */
2450    if (ep->part->type == EDJE_PART_TYPE_GRADIENT)
2451      {
2452         ERR("GRADIENT spotted during recalc ! That should never happen ! Send your edje file to devel ml.");
2453         return;
2454      }
2455
2456    if ((ep->calculated & FLAG_XY) == FLAG_XY && !state)
2457      {
2458         return;
2459      }
2460    if (ep->calculating & flags)
2461      {
2462 #if 1
2463         const char *axes = "NONE", *faxes = "NONE";
2464
2465         if ((ep->calculating & FLAG_X) &&
2466             (ep->calculating & FLAG_Y))
2467           axes = "XY";
2468         else if ((ep->calculating & FLAG_X))
2469           axes = "X";
2470         else if ((ep->calculating & FLAG_Y))
2471           axes = "Y";
2472
2473         if ((flags & FLAG_X) &&
2474             (flags & FLAG_Y))
2475           faxes = "XY";
2476         else if ((flags & FLAG_X))
2477           faxes = "X";
2478         else if ((flags & FLAG_Y))
2479           faxes = "Y";
2480         ERR("Circular dependency when calculating part \"%s\". "
2481             "Already calculating %s [%02x] axes. "
2482             "Need to calculate %s [%02x] axes",
2483             ep->part->name,
2484             axes, ep->calculating,
2485             faxes, flags);
2486 #endif
2487         return;
2488      }
2489
2490    if (ep->part->scale &&
2491        ep->part->type == EDJE_PART_TYPE_GROUP &&
2492        ep->swallowed_object)
2493      {
2494         edje_object_scale_set(ep->swallowed_object, TO_DOUBLE(ed->scale));
2495
2496         if (ep->description_pos > FROM_DOUBLE(0.5) && ep->param2)
2497           {
2498              edje_object_update_hints_set(ep->swallowed_object, ep->param2->description->min.limit);
2499           }
2500         else
2501           {
2502              edje_object_update_hints_set(ep->swallowed_object, ep->param1.description->min.limit);
2503           }
2504         if (edje_object_update_hints_get(ep->swallowed_object))
2505           {
2506              Edje *ted;
2507
2508              ted = _edje_fetch(ep->swallowed_object);
2509              _edje_recalc_do(ted);
2510           }
2511      }
2512
2513 #ifdef EDJE_CALC_CACHE
2514    if (ep->state == ed->state && !state)
2515      return;
2516 #endif
2517
2518    if (flags & FLAG_X)
2519      {
2520         ep->calculating |= flags & FLAG_X;
2521         if (ep->param1.rel1_to_x)
2522           {
2523              _edje_part_recalc(ed, ep->param1.rel1_to_x, FLAG_X, NULL);
2524 #ifdef EDJE_CALC_CACHE
2525              state1 = ep->param1.rel1_to_x->state;
2526 #endif
2527           }
2528         if (ep->param1.rel2_to_x)
2529           {
2530              _edje_part_recalc(ed, ep->param1.rel2_to_x, FLAG_X, NULL);
2531 #ifdef EDJE_CALC_CACHE
2532              if (state1 < ep->param1.rel2_to_x->state)
2533                state1 = ep->param1.rel2_to_x->state;
2534 #endif
2535           }
2536         if (ep->param2)
2537           {
2538              if (ep->param2->rel1_to_x)
2539                {
2540                   _edje_part_recalc(ed, ep->param2->rel1_to_x, FLAG_X, NULL);
2541 #ifdef EDJE_CALC_CACHE
2542                   state2 = ep->param2->rel1_to_x->state;
2543 #endif
2544                }
2545              if (ep->param2->rel2_to_x)
2546                {
2547                   _edje_part_recalc(ed, ep->param2->rel2_to_x, FLAG_X, NULL);
2548 #ifdef EDJE_CALC_CACHE
2549                   if (state2 < ep->param2->rel2_to_x->state)
2550                     state2 = ep->param2->rel2_to_x->state;
2551 #endif
2552                }
2553           }
2554      }
2555    if (flags & FLAG_Y)
2556      {
2557         ep->calculating |= flags & FLAG_Y;
2558         if (ep->param1.rel1_to_y)
2559           {
2560              _edje_part_recalc(ed, ep->param1.rel1_to_y, FLAG_Y, NULL);
2561 #ifdef EDJE_CALC_CACHE
2562              if (state1 < ep->param1.rel1_to_y->state)
2563                state1 = ep->param1.rel1_to_y->state;
2564 #endif
2565           }
2566         if (ep->param1.rel2_to_y)
2567           {
2568              _edje_part_recalc(ed, ep->param1.rel2_to_y, FLAG_Y, NULL);
2569 #ifdef EDJE_CALC_CACHE
2570              if (state1 < ep->param1.rel2_to_y->state)
2571                state1 = ep->param1.rel2_to_y->state;
2572 #endif
2573           }
2574         if (ep->param2)
2575           {
2576              if (ep->param2->rel1_to_y)
2577                {
2578                   _edje_part_recalc(ed, ep->param2->rel1_to_y, FLAG_Y, NULL);
2579 #ifdef EDJE_CALC_CACHE
2580                   if (state2 < ep->param2->rel1_to_y->state)
2581                     state2 = ep->param2->rel1_to_y->state;
2582 #endif
2583                }
2584              if (ep->param2->rel2_to_y)
2585                {
2586                   _edje_part_recalc(ed, ep->param2->rel2_to_y, FLAG_Y, NULL);
2587 #ifdef EDJE_CALC_CACHE
2588                   if (state2 < ep->param2->rel2_to_y->state)
2589                     state2 = ep->param2->rel2_to_y->state;
2590 #endif
2591                }
2592           }
2593      }
2594    if (ep->drag && ep->drag->confine_to)
2595      {
2596         confine_to = ep->drag->confine_to;
2597         _edje_part_recalc(ed, confine_to, flags, NULL);
2598 #ifdef EDJE_CALC_CACHE
2599         statec = confine_to->state;
2600 #endif
2601      }
2602    //   if (ep->text.source)       _edje_part_recalc(ed, ep->text.source, flags);
2603    //   if (ep->text.text_source)  _edje_part_recalc(ed, ep->text.text_source, flags);
2604
2605    /* actually calculate now */
2606    chosen_desc = ep->chosen_description;
2607    if (!chosen_desc)
2608      {
2609         ep->calculating = FLAG_NONE;
2610         ep->calculated |= flags;
2611         return;
2612      }
2613
2614    pos = ep->description_pos;
2615
2616    if (ep->part->type == EDJE_PART_TYPE_PROXY)
2617      {
2618         Edje_Real_Part *pp;
2619         int part_id = -1;
2620
2621         if (pos >= FROM_DOUBLE(0.5))
2622           part_id = ((Edje_Part_Description_Proxy *)ep->param2->description)->proxy.id;
2623         else
2624           part_id = ((Edje_Part_Description_Proxy *)chosen_desc)->proxy.id;
2625
2626         pp = _edje_real_part_state_get(ed, ep, flags, part_id, NULL);
2627 #ifdef EDJE_CALC_CACHE
2628         if (pp && pp->invalidate) proxy_invalidate = EINA_TRUE;
2629 #endif
2630      }
2631
2632    /* Recalc if needed the map center && light source */
2633    if (ep->param1.description->map.on)
2634      {
2635         center[0] = _edje_real_part_state_get(ed, ep, flags, ep->param1.description->map.rot.id_center, &statec1);
2636         light[0] = _edje_real_part_state_get(ed, ep, flags, ep->param1.description->map.id_light, &statel1);
2637
2638         if (chosen_desc->map.persp_on)
2639           {
2640              persp[0] = _edje_real_part_state_get(ed, ep, flags, ep->param1.description->map.id_persp, &statep1);
2641           }
2642      }
2643
2644    if (ep->param2 && ep->param2->description->map.on)
2645      {
2646         center[1] = _edje_real_part_state_get(ed, ep, flags, ep->param2->description->map.rot.id_center, &statec2);
2647         light[1] = _edje_real_part_state_get(ed, ep, flags, ep->param2->description->map.id_light, &statel2);
2648
2649         if (chosen_desc->map.persp_on)
2650           {
2651              persp[1] = _edje_real_part_state_get(ed, ep, flags, ep->param2->description->map.id_persp, &statep2);
2652           }
2653      }
2654
2655 #ifndef EDJE_CALC_CACHE
2656    p1 = &lp1;
2657 #else
2658    p1 = &ep->param1.p;
2659 #endif
2660
2661    if (ep->param1.description)
2662      {
2663 #ifdef EDJE_CALC_CACHE
2664         if (ed->all_part_change ||
2665             ep->invalidate ||
2666             state1 >= ep->param1.state ||
2667             statec >= ep->param1.state ||
2668             statec1 >= ep->param1.state ||
2669             statel1 >= ep->param1.state ||
2670             statep1 >= ep->param1.state ||
2671             proxy_invalidate ||
2672             state ||
2673             ((ep->part->type == EDJE_PART_TYPE_TEXT || ep->part->type == EDJE_PART_TYPE_TEXTBLOCK) && ed->text_part_change))
2674 #endif
2675         {
2676            _edje_part_recalc_single(ed, ep, ep->param1.description, chosen_desc, center[0], light[0], persp[0],
2677                                     ep->param1.rel1_to_x, ep->param1.rel1_to_y, ep->param1.rel2_to_x, ep->param1.rel2_to_y,
2678                                     confine_to,
2679                                     p1, pos);
2680
2681 #ifdef EDJE_CALC_CACHE
2682            if (flags == FLAG_XY)
2683              ep->param1.state = ed->state;
2684 #endif
2685         }
2686      }
2687    if (ep->param2)
2688      {
2689         int beginning_pos, part_type;
2690         Edje_Calc_Params *p2, *p3;
2691
2692         if (ep->current)
2693           {
2694              /* FIXME: except for text, we don't need in that case to recalc p1 at all*/
2695              memcpy(p1, ep->current, sizeof (Edje_Calc_Params));
2696           }
2697
2698         p3 = &lp3;
2699
2700 #ifndef EDJE_CALC_CACHE
2701         p2 = &lp2;
2702 #else
2703         p2 = &ep->param2->p;
2704
2705         if (ed->all_part_change ||
2706             ep->invalidate ||
2707             state2 >= ep->param2->state ||
2708             statec >= ep->param2->state ||
2709             statec2 >= ep->param2->state ||
2710             statel2 >= ep->param2->state ||
2711             statep2 >= ep->param2->state ||
2712             proxy_invalidate ||
2713             state ||
2714             ((ep->part->type == EDJE_PART_TYPE_TEXT || ep->part->type == EDJE_PART_TYPE_TEXTBLOCK) && ed->text_part_change))
2715 #endif
2716         {
2717            _edje_part_recalc_single(ed, ep, ep->param2->description,
2718                                     chosen_desc,
2719                                     center[1], light[1], persp[1],
2720                                     ep->param2->rel1_to_x,
2721                                     ep->param2->rel1_to_y,
2722                                     ep->param2->rel2_to_x,
2723                                     ep->param2->rel2_to_y,
2724                                     confine_to,
2725                                     p2, pos);
2726 #ifdef EDJE_CALC_CACHE
2727            if (flags == FLAG_XY)
2728              ep->param2->state = ed->state;
2729 #endif
2730         }
2731
2732         pos2 = pos;
2733         if (pos2 < ZERO) pos2 = ZERO;
2734         else if (pos2 > FROM_INT(1))
2735           pos2 = FROM_INT(1);
2736         beginning_pos = (pos < FROM_DOUBLE(0.5));
2737         part_type = ep->part->type;
2738
2739         /* visible is special */
2740         if ((p1->visible) && (!p2->visible))
2741           p3->visible = (pos != FROM_INT(1));
2742         else if ((!p1->visible) && (p2->visible))
2743           p3->visible = (pos != ZERO);
2744         else
2745           p3->visible = p1->visible;
2746
2747         p3->smooth = (beginning_pos) ? p1->smooth : p2->smooth;
2748
2749         /* FIXME: do x and y separately base on flag */
2750 #define FINTP(_x1, _x2, _p) \
2751   (((_x1) == (_x2))         \
2752    ? FROM_INT((_x1))        \
2753    : ADD(FROM_INT(_x1),     \
2754          SCALE((_p), (_x2) - (_x1))))
2755
2756 #define FFP(_x1, _x2, _p) \
2757   (((_x1) == (_x2))       \
2758    ? (_x1)                \
2759    : ADD(_x1, MUL(_p, SUB(_x2, _x1))));
2760
2761 #define INTP(_x1, _x2, _p) TO_INT(FINTP(_x1, _x2, _p))
2762
2763         p3->x = INTP(p1->x, p2->x, pos);
2764         p3->y = INTP(p1->y, p2->y, pos);
2765         p3->w = INTP(p1->w, p2->w, pos);
2766         p3->h = INTP(p1->h, p2->h, pos);
2767
2768         p3->req.x = INTP(p1->req.x, p2->req.x, pos);
2769         p3->req.y = INTP(p1->req.y, p2->req.y, pos);
2770         p3->req.w = INTP(p1->req.w, p2->req.w, pos);
2771         p3->req.h = INTP(p1->req.h, p2->req.h, pos);
2772
2773         if (ep->part->dragable.x)
2774           {
2775              p3->req_drag.x = INTP(p1->req_drag.x, p2->req_drag.x, pos);
2776              p3->req_drag.w = INTP(p1->req_drag.w, p2->req_drag.w, pos);
2777           }
2778         if (ep->part->dragable.y)
2779           {
2780              p3->req_drag.y = INTP(p1->req_drag.y, p2->req_drag.y, pos);
2781              p3->req_drag.h = INTP(p1->req_drag.h, p2->req_drag.h, pos);
2782           }
2783
2784         p3->color.r = INTP(p1->color.r, p2->color.r, pos2);
2785         p3->color.g = INTP(p1->color.g, p2->color.g, pos2);
2786         p3->color.b = INTP(p1->color.b, p2->color.b, pos2);
2787         p3->color.a = INTP(p1->color.a, p2->color.a, pos2);
2788
2789         switch (part_type)
2790           {
2791            case EDJE_PART_TYPE_IMAGE:
2792              p3->type.common.spec.image.l = INTP(p1->type.common.spec.image.l, p2->type.common.spec.image.l, pos);
2793              p3->type.common.spec.image.r = INTP(p1->type.common.spec.image.r, p2->type.common.spec.image.r, pos);
2794              p3->type.common.spec.image.t = INTP(p1->type.common.spec.image.t, p2->type.common.spec.image.t, pos);
2795              p3->type.common.spec.image.b = INTP(p1->type.common.spec.image.b, p2->type.common.spec.image.b, pos);
2796              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);
2797
2798            case EDJE_PART_TYPE_PROXY:
2799              p3->type.common.fill.x = INTP(p1->type.common.fill.x, p2->type.common.fill.x, pos);
2800              p3->type.common.fill.y = INTP(p1->type.common.fill.y, p2->type.common.fill.y, pos);
2801              p3->type.common.fill.w = INTP(p1->type.common.fill.w, p2->type.common.fill.w, pos);
2802              p3->type.common.fill.h = INTP(p1->type.common.fill.h, p2->type.common.fill.h, pos);
2803              break;
2804
2805            case EDJE_PART_TYPE_TEXT:
2806              p3->type.text.size = INTP(p1->type.text.size, p2->type.text.size, pos);
2807
2808            case EDJE_PART_TYPE_TEXTBLOCK:
2809              p3->type.text.color2.r = INTP(p1->type.text.color2.r, p2->type.text.color2.r, pos2);
2810              p3->type.text.color2.g = INTP(p1->type.text.color2.g, p2->type.text.color2.g, pos2);
2811              p3->type.text.color2.b = INTP(p1->type.text.color2.b, p2->type.text.color2.b, pos2);
2812              p3->type.text.color2.a = INTP(p1->type.text.color2.a, p2->type.text.color2.a, pos2);
2813
2814              p3->type.text.color3.r = INTP(p1->type.text.color3.r, p2->type.text.color3.r, pos2);
2815              p3->type.text.color3.g = INTP(p1->type.text.color3.g, p2->type.text.color3.g, pos2);
2816              p3->type.text.color3.b = INTP(p1->type.text.color3.b, p2->type.text.color3.b, pos2);
2817              p3->type.text.color3.a = INTP(p1->type.text.color3.a, p2->type.text.color3.a, pos2);
2818
2819              p3->type.text.align.x = FFP(p1->type.text.align.x, p2->type.text.align.x, pos);
2820              p3->type.text.align.y = FFP(p1->type.text.align.y, p2->type.text.align.y, pos);
2821              p3->type.text.elipsis = TO_DOUBLE(FINTP(p1->type.text.elipsis, p2->type.text.elipsis, pos2));
2822              break;
2823           }
2824
2825         p3->mapped = p1->mapped;
2826         p3->persp_on = p3->mapped ? p1->persp_on | p2->persp_on : 0;
2827         p3->lighted = p3->mapped ? p1->lighted | p2->lighted : 0;
2828         if (p1->mapped)
2829           {
2830              p3->map.center.x = INTP(p1->map.center.x, p2->map.center.x, pos);
2831              p3->map.center.y = INTP(p1->map.center.y, p2->map.center.y, pos);
2832              p3->map.center.z = INTP(p1->map.center.z, p2->map.center.z, pos);
2833              p3->map.rotation.x = FFP(p1->map.rotation.x, p2->map.rotation.x, pos);
2834              p3->map.rotation.y = FFP(p1->map.rotation.y, p2->map.rotation.y, pos);
2835              p3->map.rotation.z = FFP(p1->map.rotation.z, p2->map.rotation.z, pos);
2836
2837 #define MIX(P1, P2, P3, pos, info) \
2838   P3->info = P1->info + TO_INT(SCALE(pos, P2->info - P1->info));
2839
2840              if (p1->lighted && p2->lighted)
2841                {
2842                   MIX(p1, p2, p3, pos, map.light.x);
2843                   MIX(p1, p2, p3, pos, map.light.y);
2844                   MIX(p1, p2, p3, pos, map.light.z);
2845                   MIX(p1, p2, p3, pos, map.light.r);
2846                   MIX(p1, p2, p3, pos, map.light.g);
2847                   MIX(p1, p2, p3, pos, map.light.b);
2848                   MIX(p1, p2, p3, pos, map.light.ar);
2849                   MIX(p1, p2, p3, pos, map.light.ag);
2850                   MIX(p1, p2, p3, pos, map.light.ab);
2851                }
2852              else if (p1->lighted)
2853                {
2854                   memcpy(&p3->map.light, &p1->map.light, sizeof (p1->map.light));
2855                }
2856              else if (p2->lighted)
2857                {
2858                   memcpy(&p3->map.light, &p2->map.light, sizeof (p2->map.light));
2859                }
2860
2861              if (p1->persp_on && p2->persp_on)
2862                {
2863                   MIX(p1, p2, p3, pos, map.persp.x);
2864                   MIX(p1, p2, p3, pos, map.persp.y);
2865                   MIX(p1, p2, p3, pos, map.persp.z);
2866                   MIX(p1, p2, p3, pos, map.persp.focal);
2867                }
2868              else if (p1->persp_on)
2869                {
2870                   memcpy(&p3->map.persp, &p1->map.persp, sizeof (p1->map.persp));
2871                }
2872              else if (p2->persp_on)
2873                {
2874                   memcpy(&p3->map.persp, &p2->map.persp, sizeof (p2->map.persp));
2875                }
2876           }
2877
2878         pf = p3;
2879      }
2880    else
2881      {
2882         pf = p1;
2883      }
2884
2885    if (!pf->persp_on && chosen_desc->map.persp_on)
2886      {
2887         if (ed->persp)
2888           {
2889              pf->map.persp.x = ed->persp->px;
2890              pf->map.persp.y = ed->persp->py;
2891              pf->map.persp.z = ed->persp->z0;
2892              pf->map.persp.focal = ed->persp->foc;
2893           }
2894         else
2895           {
2896              const Edje_Perspective *ps;
2897
2898              // fixme: a tad inefficient as this is a has lookup
2899              ps = edje_object_perspective_get(ed->obj);
2900              if (!ps)
2901                ps = edje_evas_global_perspective_get(evas_object_evas_get(ed->obj));
2902              if (ps)
2903                {
2904                   pf->map.persp.x = ps->px;
2905                   pf->map.persp.y = ps->py;
2906                   pf->map.persp.z = ps->z0;
2907                   pf->map.persp.focal = ps->foc;
2908                }
2909              else
2910                {
2911                   pf->map.persp.x = ed->x + (ed->w / 2);
2912                   pf->map.persp.y = ed->y + (ed->h / 2);
2913                   pf->map.persp.z = 0;
2914                   pf->map.persp.focal = 1000;
2915                }
2916           }
2917      }
2918
2919    if (state)
2920      {
2921         memcpy(state, pf, sizeof (Edje_Calc_Params));
2922      }
2923
2924    ep->req = pf->req;
2925
2926    if (ep->drag && ep->drag->need_reset)
2927      {
2928         FLOAT_T dx, dy;
2929
2930         dx = ZERO;
2931         dy = ZERO;
2932         _edje_part_dragable_calc(ed, ep, &dx, &dy);
2933         ep->drag->x = dx;
2934         ep->drag->y = dy;
2935         ep->drag->tmp.x = 0;
2936         ep->drag->tmp.y = 0;
2937         ep->drag->need_reset = 0;
2938      }
2939    if (!ed->calc_only)
2940      {
2941         Evas_Object *mo;
2942
2943         /* Common move, resize and color_set for all part. */
2944         switch (ep->part->type)
2945           {
2946            case EDJE_PART_TYPE_IMAGE:
2947            {
2948               Edje_Part_Description_Image *img_desc = (Edje_Part_Description_Image *)chosen_desc;
2949
2950               evas_object_image_scale_hint_set(ep->object,
2951                                                img_desc->image.scale_hint);
2952            }
2953
2954            case EDJE_PART_TYPE_PROXY:
2955            case EDJE_PART_TYPE_RECTANGLE:
2956            case EDJE_PART_TYPE_TEXTBLOCK:
2957            case EDJE_PART_TYPE_BOX:
2958            case EDJE_PART_TYPE_TABLE:
2959              evas_object_color_set(ep->object,
2960                                    (pf->color.r * pf->color.a) / 255,
2961                                    (pf->color.g * pf->color.a) / 255,
2962                                    (pf->color.b * pf->color.a) / 255,
2963                                    pf->color.a);
2964              if (!pf->visible)
2965                {
2966                   evas_object_hide(ep->object);
2967                   break;
2968                }
2969              evas_object_show(ep->object);
2970
2971            /* move and resize are needed for all previous object => no break here. */
2972            case EDJE_PART_TYPE_SWALLOW:
2973            case EDJE_PART_TYPE_GROUP:
2974            case EDJE_PART_TYPE_EXTERNAL:
2975              /* visibility and color have no meaning on SWALLOW and GROUP part. */
2976              evas_object_move(ep->object, ed->x + pf->x, ed->y + pf->y);
2977              evas_object_resize(ep->object, pf->w, pf->h);
2978              if (ep->part->entry_mode > EDJE_ENTRY_EDIT_MODE_NONE)
2979                _edje_entry_real_part_configure(ep);
2980              break;
2981
2982            case EDJE_PART_TYPE_TEXT:
2983              /* This is correctly handle in _edje_text_recalc_apply at the moment. */
2984              break;
2985
2986            case EDJE_PART_TYPE_GRADIENT:
2987              /* FIXME: definitivly remove this code when we switch to new format. */
2988              abort();
2989              break;
2990
2991            case EDJE_PART_TYPE_SPACER:
2992              /* We really should do nothing on SPACER part */
2993              break;
2994           }
2995
2996         /* Some object need special recalc. */
2997         switch (ep->part->type)
2998           {
2999            case EDJE_PART_TYPE_TEXT:
3000              _edje_text_recalc_apply(ed, ep, pf, (Edje_Part_Description_Text *)chosen_desc);
3001              break;
3002
3003            case EDJE_PART_TYPE_PROXY:
3004              _edje_proxy_recalc_apply(ed, ep, pf, (Edje_Part_Description_Proxy *)chosen_desc, pos);
3005              break;
3006
3007            case EDJE_PART_TYPE_IMAGE:
3008              _edje_image_recalc_apply(ed, ep, pf, (Edje_Part_Description_Image *)chosen_desc, pos);
3009              break;
3010
3011            case EDJE_PART_TYPE_BOX:
3012              _edje_box_recalc_apply(ed, ep, pf, (Edje_Part_Description_Box *)chosen_desc);
3013              break;
3014
3015            case EDJE_PART_TYPE_TABLE:
3016              _edje_table_recalc_apply(ed, ep, pf, (Edje_Part_Description_Table *)chosen_desc);
3017              break;
3018
3019            case EDJE_PART_TYPE_TEXTBLOCK:
3020              _edje_textblock_recalc_apply(ed, ep, pf, (Edje_Part_Description_Text *)chosen_desc);
3021              break;
3022
3023            case EDJE_PART_TYPE_EXTERNAL:
3024            case EDJE_PART_TYPE_RECTANGLE:
3025            case EDJE_PART_TYPE_SWALLOW:
3026            case EDJE_PART_TYPE_GROUP:
3027              /* Nothing special to do for this type of object. */
3028              break;
3029
3030            case EDJE_PART_TYPE_GRADIENT:
3031              /* FIXME: definitivly remove this code when we switch to new format. */
3032              abort();
3033              break;
3034
3035            case EDJE_PART_TYPE_SPACER:
3036              /* We really should do nothing on SPACER part */
3037              break;
3038           }
3039
3040         if (ep->swallowed_object)
3041           {
3042              //// the below really is wrong - swallow color shouldn't affect swallowed object
3043              //// color - the edje color as a WHOLE should though - and that should be
3044              //// done via the clipper anyway. this created bugs when objects had their
3045              //// colro set and were swallowed - then had their color changed.
3046              //      evas_object_color_set(ep->swallowed_object,
3047              //                            (pf->color.r * pf->color.a) / 255,
3048              //                            (pf->color.g * pf->color.a) / 255,
3049              //                            (pf->color.b * pf->color.a) / 255,
3050              //                            pf->color.a);
3051              if (pf->visible)
3052                {
3053                   evas_object_move(ep->swallowed_object, ed->x + pf->x, ed->y + pf->y);
3054                   evas_object_resize(ep->swallowed_object, pf->w, pf->h);
3055                   evas_object_show(ep->swallowed_object);
3056                }
3057              else evas_object_hide(ep->swallowed_object);
3058              mo = ep->swallowed_object;
3059           }
3060         else mo = ep->object;
3061         if (chosen_desc->map.on && ep->part->type != EDJE_PART_TYPE_SPACER)
3062           {
3063              static Evas_Map *map = NULL;
3064
3065              ed->have_mapped_part = 1;
3066              // create map and populate with part geometry
3067              if (!map) map = evas_map_new(4);
3068              evas_map_util_points_populate_from_object(map, ep->object);
3069              if (ep->part->type == EDJE_PART_TYPE_IMAGE ||
3070                  ((ep->part->type == EDJE_PART_TYPE_SWALLOW) &&
3071                   (!strcmp(evas_object_type_get(mo), "image") &&
3072                    (!evas_object_image_source_get(mo))))
3073                  )
3074                {
3075                   int iw = 1, ih = 1;
3076
3077                   evas_object_image_size_get(mo, &iw, &ih);
3078                   evas_map_point_image_uv_set(map, 0, 0.0, 0.0);
3079                   evas_map_point_image_uv_set(map, 1, iw, 0.0);
3080                   evas_map_point_image_uv_set(map, 2, iw, ih);
3081                   evas_map_point_image_uv_set(map, 3, 0.0, ih);
3082                }
3083              evas_map_util_3d_rotate(map,
3084                                      TO_DOUBLE(pf->map.rotation.x), TO_DOUBLE(pf->map.rotation.y), TO_DOUBLE(pf->map.rotation.z),
3085                                      pf->map.center.x, pf->map.center.y, pf->map.center.z);
3086
3087              // calculate light color & position etc. if there is one
3088              if (pf->lighted)
3089                {
3090                   evas_map_util_3d_lighting(map,
3091                                             pf->map.light.x, pf->map.light.y, pf->map.light.z,
3092                                             pf->map.light.r, pf->map.light.g, pf->map.light.b,
3093                                             pf->map.light.ar, pf->map.light.ag, pf->map.light.ab);
3094                }
3095
3096              // calculate perspective point
3097              if (chosen_desc->map.persp_on)
3098                {
3099                   evas_map_util_3d_perspective(map,
3100                                                pf->map.persp.x, pf->map.persp.y, pf->map.persp.z,
3101                                                pf->map.persp.focal);
3102                }
3103
3104              // handle backface culling (object is facing away from view
3105              if (chosen_desc->map.backcull)
3106                {
3107                   if (pf->visible)
3108                     {
3109                        if (evas_map_util_clockwise_get(map))
3110                          evas_object_show(mo);
3111                        else evas_object_hide(mo);
3112                     }
3113                }
3114
3115              // handle smooth
3116              if (chosen_desc->map.smooth) evas_map_smooth_set(map, 1);
3117              else evas_map_smooth_set(map, 0);
3118              // handle alpha
3119              if (chosen_desc->map.alpha) evas_map_alpha_set(map, 1);
3120              else evas_map_alpha_set(map, 0);
3121
3122              evas_object_map_set(mo, map);
3123              evas_object_map_enable_set(mo, 1);
3124           }
3125         else
3126           {
3127              evas_object_map_enable_set(mo, 0);
3128              evas_object_map_set(mo, NULL);
3129           }
3130      }
3131
3132    ep->x = pf->x;
3133    ep->y = pf->y;
3134    ep->w = pf->w;
3135    ep->h = pf->h;
3136
3137    ep->calculated |= flags;
3138    ep->calculating = FLAG_NONE;
3139
3140 #ifdef EDJE_CALC_CACHE
3141    if (ep->calculated == FLAG_XY)
3142      {
3143         ep->state = ed->state;
3144         ep->invalidate = 0;
3145      }
3146 #endif
3147 }
3148