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