mobile_lib/ctxpopup : fix item part text and icon set logic 27/138527/2
authorJEONGHYUN YUN <jh0506.yun@samsung.com>
Wed, 12 Jul 2017 11:38:25 +0000 (20:38 +0900)
committerGerrit Code Review <gerrit@review.ap-northeast-2.compute.internal>
Thu, 13 Jul 2017 22:46:45 +0000 (22:46 +0000)
when icon or text is null, theme will be changed if it needs

Change-Id: I58c0377e0149bdbcd256c55eaf9e7904cf08f186
Signed-off-by: JEONGHYUN YUN <jh0506.yun@samsung.com>
src/mobile_lib/elc_ctxpopup.c

index 3bb6295c3784a4d2715713b603991b720c303721..6b1628a1c2779c27f3d2224499307e982e68dc58 100644 (file)
@@ -407,32 +407,6 @@ _item_theme_set(Elm_Ctxpopup_Item_Data *item,
      item);
 }
 
-static void
-_item_icon_set(Elm_Ctxpopup_Item_Data *item,
-               Evas_Object *icon)
-{
-   if (item->icon)
-     evas_object_del(item->icon);
-
-   item->icon = icon;
-   if (!icon) return;
-
-   edje_object_part_swallow(VIEW(item), "elm.swallow.icon", item->icon);
-}
-
-static void
-_item_label_set(Elm_Ctxpopup_Item_Data *item,
-                const char *label)
-{
-   if (!eina_stringshare_replace(&item->label, label))
-     return;
-
-   ELM_CTXPOPUP_DATA_GET(WIDGET(item), sd);
-
-   edje_object_part_text_set(VIEW(item), "elm.text", label);
-   if (sd->visible) _item_sizing_eval(item);
-}
-
 static Evas_Object *
 _item_in_focusable_button(Elm_Ctxpopup_Item_Data *item)
 {
@@ -1566,9 +1540,57 @@ _elm_ctxpopup_item_elm_widget_item_part_text_set(Eo *eo_ctxpopup_it EINA_UNUSED,
                                                  const char *part,
                                                  const char *label)
 {
+   if (!ctxpopup_it) return;
+   if (ctxpopup_it->label == label) return;
    if ((part) && (strcmp(part, "default"))) return;
 
-   _item_label_set(ctxpopup_it, label);
+   ELM_CTXPOPUP_DATA_GET(WIDGET(ctxpopup_it), sd);
+
+   if (ctxpopup_it->label && !label)
+     {
+        if (!sd->horizontal)
+          _elm_theme_object_set(WIDGET(ctxpopup_it), VIEW(ctxpopup_it), "ctxpopup",
+                                "icon_style_item",
+                                elm_widget_style_get(WIDGET(ctxpopup_it)));
+        else
+          _elm_theme_object_set(WIDGET(ctxpopup_it), VIEW(ctxpopup_it), "ctxpopup",
+                                "icon_style_item_horizontal",
+                                elm_widget_style_get(WIDGET(ctxpopup_it)));
+     }
+   else if (!ctxpopup_it->label && label)
+     {
+        if (!ctxpopup_it->icon)
+          {
+             if (!sd->horizontal)
+               _elm_theme_object_set(WIDGET(ctxpopup_it), VIEW(ctxpopup_it), "ctxpopup",
+                                     "text_style_item",
+                                     elm_widget_style_get(WIDGET(ctxpopup_it)));
+             else
+               _elm_theme_object_set(WIDGET(ctxpopup_it), VIEW(ctxpopup_it), "ctxpopup",
+                                     "text_style_item_horizontal",
+                                     elm_widget_style_get(WIDGET(ctxpopup_it)));
+          }
+        else
+          {
+             if (!sd->horizontal)
+               _elm_theme_object_set(WIDGET(ctxpopup_it), VIEW(ctxpopup_it), "ctxpopup",
+                                    "icon_text_style_item",
+                                    elm_widget_style_get(WIDGET(ctxpopup_it)));
+             else
+               _elm_theme_object_set(WIDGET(ctxpopup_it), VIEW(ctxpopup_it), "ctxpopup",
+                                     "icon_text_style_item_horizontal",
+                                     elm_widget_style_get(WIDGET(ctxpopup_it)));
+          }
+     }
+
+   eina_stringshare_replace(&ctxpopup_it->label, label);
+   if (ctxpopup_it->label)
+     edje_object_part_text_set(VIEW(ctxpopup_it), "elm.text", label);
+
+   sd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
+
+   if (sd->visible)
+     elm_layout_sizing_eval(WIDGET(ctxpopup_it));
 }
 
 EOLIAN static const char *
@@ -1587,11 +1609,45 @@ _elm_ctxpopup_item_elm_widget_item_part_content_set(Eo *eo_ctxpopup_it EINA_UNUS
                                                     const char *part,
                                                     Evas_Object *content)
 {
+   if (!ctxpopup_it) return;
+   if (ctxpopup_it->icon == content) return;
    if ((part) && (strcmp(part, "icon"))) return;
 
    ELM_CTXPOPUP_DATA_GET(WIDGET(ctxpopup_it), sd);
 
-   _item_icon_set(ctxpopup_it, content);
+   if (ctxpopup_it->icon)
+     evas_object_del(ctxpopup_it->icon);
+
+   if (ctxpopup_it->label)
+     {
+        if (!ctxpopup_it->icon && content)
+          {
+             if (!sd->horizontal)
+               _elm_theme_object_set(WIDGET(ctxpopup_it), VIEW(ctxpopup_it), "ctxpopup",
+                                     "icon_text_style_item",
+                                     elm_widget_style_get(WIDGET(ctxpopup_it)));
+             else
+               _elm_theme_object_set(WIDGET(ctxpopup_it), VIEW(ctxpopup_it), "ctxpopup",
+                                     "icon_text_style_item_horizontal",
+                                     elm_widget_style_get(WIDGET(ctxpopup_it)));
+          }
+        else if (ctxpopup_it->icon && !content)
+          {
+             if (!sd->horizontal)
+               _elm_theme_object_set(WIDGET(ctxpopup_it), VIEW(ctxpopup_it), "ctxpopup",
+                                     "text_style_item",
+                                     elm_widget_style_get(WIDGET(ctxpopup_it)));
+             else
+               _elm_theme_object_set(WIDGET(ctxpopup_it), VIEW(ctxpopup_it), "ctxpopup",
+                                     "text_style_item_horizontal",
+                                     elm_widget_style_get(WIDGET(ctxpopup_it)));
+          }
+     }
+
+   ctxpopup_it->icon = content;
+   if (ctxpopup_it->icon)
+     edje_object_part_swallow(VIEW(ctxpopup_it), "elm.swallow.icon", ctxpopup_it->icon);
+
    sd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
 
    if (sd->visible)
@@ -2222,8 +2278,18 @@ _item_new(Evas_Object *obj,
           _item_theme_set(item, "icon_style_item_horizontal");
      }
 
-   _item_icon_set(item, icon);
-   _item_label_set(item, label);
+   if (label)
+     {
+        edje_object_part_text_set(VIEW(item), "elm.text", label);
+        item->label = eina_stringshare_add(label);
+     }
+
+   if (icon)
+     {
+        edje_object_part_swallow(VIEW(item), "elm.swallow.icon", icon);
+        item->icon = icon;
+     }
+
    focus_bt = _item_in_focusable_button(item);
    item->btn = focus_bt;
    _elm_widget_color_class_parent_set(VIEW(item), obj);