[els_icon.c]Merge opensource els_icon.c bug fix to resolve GUI Builder issue
[framework/uifw/elementary.git] / src / lib / els_icon.c
old mode 100755 (executable)
new mode 100644 (file)
index 4cc5343..f32ab4d
@@ -24,7 +24,7 @@ struct _Smart_Data
    Eina_Bool show : 1;
    Eina_Bool edit : 1;
    Eina_Bool edje : 1;
-   Eina_Bool aspect_ratio_retained: 1;
+   Eina_Bool aspect_fixed: 1;
    Elm_Image_Orient orient;
 };
 
@@ -88,6 +88,7 @@ _els_smart_icon_file_helper(Evas_Object *obj)
    pclip = evas_object_clip_get(sd->obj);
    if (sd->obj) sd->prev = sd->obj;
    sd->obj = evas_object_image_add(evas_object_evas_get(obj));
+   evas_object_image_load_orientation_set(sd->obj, EINA_TRUE);
    evas_object_event_callback_add(sd->obj, EVAS_CALLBACK_IMAGE_PRELOADED,
                                   _preloaded, sd);
    evas_object_smart_member_add(sd->obj, obj);
@@ -495,27 +496,27 @@ _els_smart_icon_edje_get(Evas_Object *obj)
 }
 
 void
-_els_smart_icon_aspect_ratio_retained_set(Evas_Object *obj, Eina_Bool retained)
+_els_smart_icon_aspect_fixed_set(Evas_Object *obj, Eina_Bool fixed)
 {
    Smart_Data *sd;
 
    sd = evas_object_smart_data_get(obj);
    if (!sd) return;
 
-   retained = !!retained;
-   if (sd->aspect_ratio_retained == retained) return;
-   sd->aspect_ratio_retained = retained;
+   fixed = !!fixed;
+   if (sd->aspect_fixed == fixed) return;
+   sd->aspect_fixed = fixed;
    _smart_reconfigure(sd);
 }
 
 Eina_Bool
-_els_smart_icon_aspect_ratio_retained_get(const Evas_Object *obj)
+_els_smart_icon_aspect_fixed_get(const Evas_Object *obj)
 {
    Smart_Data *sd;
 
    sd = evas_object_smart_data_get(obj);
    if (!sd) return EINA_FALSE;
-   return sd->aspect_ratio_retained;
+   return sd->aspect_fixed;
 }
 
 /* local subsystem globals */
@@ -542,6 +543,8 @@ _smart_reconfigure(Smart_Data *sd)
    else
      {
         int iw = 0, ih = 0;
+        double alignh = 0.5, alignv = 0.5;
+        Evas_Object *parent;
 
         evas_object_image_size_get(sd->obj, &iw, &ih);
 
@@ -551,7 +554,7 @@ _smart_reconfigure(Smart_Data *sd)
         if (iw < 1) iw = 1;
         if (ih < 1) ih = 1;
 
-        if (sd->aspect_ratio_retained)
+        if (sd->aspect_fixed)
           {
              h = ((double)ih * w) / (double)iw;
              if (sd->fill_inside)
@@ -581,8 +584,13 @@ _smart_reconfigure(Smart_Data *sd)
              if (w < iw) w = iw;
              if (h < ih) h = ih;
           }
-        x = sd->x + ((sd->w - w) / 2);
-        y = sd->y + ((sd->h - h) / 2);
+        parent = elm_widget_parent_widget_get(sd->obj);
+        if (parent)
+          evas_object_size_hint_align_get(parent, &alignh, &alignv);
+        if (alignh == EVAS_HINT_FILL) alignh = 0.5;
+        if (alignv == EVAS_HINT_FILL) alignv = 0.5;
+        x = sd->x + ((sd->w - w) * alignh);
+        y = sd->y + ((sd->h - h) * alignv);
         evas_object_move(sd->obj, x, y);
         evas_object_image_fill_set(sd->obj, 0, 0, w, h);
         evas_object_resize(sd->obj, w, h);
@@ -636,7 +644,7 @@ _smart_add(Evas_Object *obj)
    sd->fill_inside = EINA_TRUE;
    sd->scale_up = EINA_TRUE;
    sd->scale_down = EINA_TRUE;
-   sd->aspect_ratio_retained = EINA_TRUE;
+   sd->aspect_fixed = EINA_TRUE;
    sd->size = 64;
    sd->scale = 1.0;
    evas_object_smart_member_add(sd->obj, obj);