[Gengrid] Fixed item_show bug. Merge from opensource r74643.
[framework/uifw/elementary.git] / src / lib / elm_list.c
index 3ca4bb0..d370baa 100644 (file)
@@ -15,18 +15,19 @@ struct _Widget_Data
    Elm_List_Mode mode;
    Elm_List_Mode h_mode;
    Evas_Coord minw[2], minh[2];
-   Eina_Bool scr_minw : 1;
-   Eina_Bool scr_minh : 1;
+   Elm_Object_Select_Mode select_mode;
    int walking;
    int movements;
-   struct {
+   struct
+     {
         Evas_Coord x, y;
-   } history[SWIPE_MOVES];
+     } history[SWIPE_MOVES];
+   Eina_Bool scr_minw : 1;
+   Eina_Bool scr_minh : 1;
    Eina_Bool swipe : 1;
    Eina_Bool fix_pending : 1;
    Eina_Bool on_hold : 1;
    Eina_Bool multi : 1;
-   Eina_Bool always_select : 1;
    Eina_Bool longpressed : 1;
    Eina_Bool wasselected : 1;
 };
@@ -132,7 +133,9 @@ _elm_list_item_free(Elm_List_Item *it)
    eina_stringshare_del(it->label);
 
    if (it->swipe_timer) ecore_timer_del(it->swipe_timer);
+   it->swipe_timer = NULL;
    if (it->long_timer) ecore_timer_del(it->long_timer);
+   it->long_timer = NULL;
    if (it->icon) evas_object_del(it->icon);
    if (it->end) evas_object_del(it->end);
 }
@@ -165,7 +168,7 @@ _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type ty
 
    /* TODO: fix logic for horizontal mode */
    if ((!strcmp(ev->keyname, "Left")) ||
-       (!strcmp(ev->keyname, "KP_Left")))
+       ((!strcmp(ev->keyname, "KP_Left")) && !ev->string))
      {
         if ((wd->h_mode) &&
             (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
@@ -179,7 +182,7 @@ _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type ty
           x -= step_x;
      }
    else if ((!strcmp(ev->keyname, "Right")) ||
-            (!strcmp(ev->keyname, "KP_Right")))
+            ((!strcmp(ev->keyname, "KP_Right")) && !ev->string))
      {
         if ((wd->h_mode) &&
             (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
@@ -193,7 +196,7 @@ _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type ty
           x += step_x;
      }
    else if ((!strcmp(ev->keyname, "Up"))  ||
-            (!strcmp(ev->keyname, "KP_Up")))
+            ((!strcmp(ev->keyname, "KP_Up")) && !ev->string))
      {
         if ((!wd->h_mode) &&
             (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
@@ -207,7 +210,7 @@ _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type ty
           y -= step_y;
      }
    else if ((!strcmp(ev->keyname, "Down")) ||
-            (!strcmp(ev->keyname, "KP_Down")))
+            ((!strcmp(ev->keyname, "KP_Down")) && !ev->string))
      {
         if ((!wd->h_mode) &&
             (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
@@ -221,7 +224,7 @@ _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type ty
           y += step_y;
      }
    else if ((!strcmp(ev->keyname, "Home")) ||
-            (!strcmp(ev->keyname, "KP_Home")))
+            ((!strcmp(ev->keyname, "KP_Home")) && !ev->string))
      {
         it = eina_list_data_get(wd->items);
         elm_list_item_bring_in((Elm_Object_Item *)it);
@@ -229,7 +232,7 @@ _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type ty
         return EINA_TRUE;
      }
    else if ((!strcmp(ev->keyname, "End")) ||
-            (!strcmp(ev->keyname, "KP_End")))
+            ((!strcmp(ev->keyname, "KP_End")) && !ev->string))
      {
         it = eina_list_data_get(eina_list_last(wd->items));
         elm_list_item_bring_in((Elm_Object_Item *)it);
@@ -237,7 +240,7 @@ _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type ty
         return EINA_TRUE;
      }
    else if ((!strcmp(ev->keyname, "Prior")) ||
-            (!strcmp(ev->keyname, "KP_Prior")))
+            ((!strcmp(ev->keyname, "KP_Prior")) && !ev->string))
      {
         if (wd->h_mode)
           {
@@ -255,7 +258,7 @@ _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type ty
           }
      }
    else if ((!strcmp(ev->keyname, "Next")) ||
-            (!strcmp(ev->keyname, "KP_Next")))
+            ((!strcmp(ev->keyname, "KP_Next")) && !ev->string))
      {
         if (wd->h_mode)
           {
@@ -444,8 +447,25 @@ static void
 _del_pre_hook(Evas_Object *obj)
 {
    Widget_Data *wd = elm_widget_data_get(obj);
+   const Eina_List *l;
+   Elm_List_Item *it;
+
+   evas_object_smart_callback_del(obj, "sub-object-del", _sub_del);
+
    if (!wd) return;
 
+   EINA_LIST_FOREACH(wd->items, l, it)
+     {
+        if (it->icon)
+           evas_object_event_callback_del(it->icon,
+                                          EVAS_CALLBACK_CHANGED_SIZE_HINTS,
+                                          _changed_size_hints);
+        if (it->end)
+           evas_object_event_callback_del(it->end,
+                                          EVAS_CALLBACK_CHANGED_SIZE_HINTS,
+                                          _changed_size_hints);
+     }
+
    evas_object_event_callback_del(wd->scr,
                                   EVAS_CALLBACK_CHANGED_SIZE_HINTS,
                                   _changed_size_hints);
@@ -702,7 +722,8 @@ _item_highlight(Elm_List_Item *it)
 
    if (!wd) return;
    ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
-   if ((it->highlighted) || (it->base.disabled)) return;
+   if ((it->highlighted) || (it->base.disabled) ||
+       (wd->select_mode == ELM_OBJECT_SELECT_MODE_NONE)) return;
 
    evas_object_ref(obj);
    _elm_list_walk(wd);
@@ -725,10 +746,10 @@ _item_select(Elm_List_Item *it)
 
    if (!wd) return;
    ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
-   if (it->base.disabled) return;
+   if (it->base.disabled || (wd->select_mode == ELM_OBJECT_SELECT_MODE_NONE)) return;
    if (it->selected)
      {
-        if (wd->always_select) goto call;
+        if (wd->select_mode == ELM_OBJECT_SELECT_MODE_ALWAYS) goto call;
         return;
      }
    it->selected = EINA_TRUE;
@@ -1031,7 +1052,7 @@ _item_disable(Elm_Object_Item *it)
 }
 
 static void
-_item_content_set(Elm_Object_Item *it, const char *part, Evas_Object *content)
+_item_content_set_hook(Elm_Object_Item *it, const char *part, Evas_Object *content)
 {
    Elm_List_Item *item = (Elm_List_Item *)it;
    Evas_Object **icon_p = NULL;
@@ -1041,15 +1062,15 @@ _item_content_set(Elm_Object_Item *it, const char *part, Evas_Object *content)
      {
         icon_p = &(item->icon);
         dummy = item->dummy_icon;
-        if (!content) item->dummy_icon = EINA_FALSE;
-        else item->dummy_icon = EINA_TRUE;
+        if (!content) item->dummy_icon = EINA_TRUE;
+        else item->dummy_icon = EINA_FALSE;
      }
    else if (!strcmp(part, "end"))
      {
         icon_p = &(item->end);
         dummy = item->dummy_end;
-        if (!content) item->dummy_end = EINA_FALSE;
-        else item->dummy_end = EINA_TRUE;
+        if (!content) item->dummy_end = EINA_TRUE;
+        else item->dummy_end = EINA_FALSE;
      }
    else
      return;
@@ -1073,7 +1094,7 @@ _item_content_set(Elm_Object_Item *it, const char *part, Evas_Object *content)
 }
 
 static Evas_Object *
-_item_content_get(const Elm_Object_Item *it, const char *part)
+_item_content_get_hook(const Elm_Object_Item *it, const char *part)
 {
    Elm_List_Item *item = (Elm_List_Item *)it;
 
@@ -1091,37 +1112,37 @@ _item_content_get(const Elm_Object_Item *it, const char *part)
 }
 
 static Evas_Object *
-_item_content_unset(const Elm_Object_Item *it, const char *part)
+_item_content_unset_hook(const Elm_Object_Item *it, const char *part)
 {
    Elm_List_Item *item = (Elm_List_Item *)it;
 
    if ((!part) || (!strcmp(part, "start")))
      {
         Evas_Object *obj = item->icon;
-        _item_content_set((Elm_Object_Item *)it, part, NULL);
+        _item_content_set_hook((Elm_Object_Item *)it, part, NULL);
         return obj;
      }
    else if (!strcmp(part, "end"))
      {
         Evas_Object *obj = item->end;
-        _item_content_set((Elm_Object_Item *)it, part, NULL);
+        _item_content_set_hook((Elm_Object_Item *)it, part, NULL);
         return obj;
      }
    return NULL;
 }
 
 static void
-_item_text_set(Elm_Object_Item *it, const char *part, const char *text)
+_item_text_set_hook(Elm_Object_Item *it, const char *part, const char *text)
 {
    Elm_List_Item *list_it = (Elm_List_Item *)it;
    if (part && strcmp(part, "default")) return;
    if (!eina_stringshare_replace(&list_it->label, text)) return;
    if (VIEW(list_it))
-     edje_object_part_text_set(VIEW(list_it), "elm.text", text);
+     edje_object_part_text_escaped_set(VIEW(list_it), "elm.text", text);
 }
 
 static const char *
-_item_text_get(const Elm_Object_Item *it, const char *part)
+_item_text_get_hook(const Elm_Object_Item *it, const char *part)
 {
    if (part && strcmp(part, "default")) return NULL;
    return ((Elm_List_Item *)it)->label;
@@ -1195,11 +1216,11 @@ _item_new(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Object *e
                                        _changed_size_hints, obj);
      }
    elm_widget_item_disable_hook_set(it, _item_disable);
-   elm_widget_item_content_set_hook_set(it, _item_content_set);
-   elm_widget_item_content_get_hook_set(it, _item_content_get);
-   elm_widget_item_content_unset_hook_set(it, _item_content_unset);
-   elm_widget_item_text_set_hook_set(it, _item_text_set);
-   elm_widget_item_text_get_hook_set(it, _item_text_get);
+   elm_widget_item_content_set_hook_set(it, _item_content_set_hook);
+   elm_widget_item_content_get_hook_set(it, _item_content_get_hook);
+   elm_widget_item_content_unset_hook_set(it, _item_content_unset_hook);
+   elm_widget_item_text_set_hook_set(it, _item_text_set_hook);
+   elm_widget_item_text_get_hook_set(it, _item_text_get_hook);
    elm_widget_item_del_pre_hook_set(it, _item_del_pre_hook);
    return it;
 }
@@ -1330,7 +1351,7 @@ _fix_items(Evas_Object *obj)
                   else if (!strcmp(stacking, "above"))
                     evas_object_raise(VIEW(it));
                }
-             edje_object_part_text_set(VIEW(it), "elm.text", it->label);
+             edje_object_part_text_escaped_set(VIEW(it), "elm.text", it->label);
 
              if ((!it->icon) && (minh[0] > 0))
                {
@@ -1622,21 +1643,24 @@ elm_list_horizontal_get(const Evas_Object *obj)
 }
 
 EAPI void
-elm_list_always_select_mode_set(Evas_Object *obj, Eina_Bool always_select)
+elm_list_select_mode_set(Evas_Object *obj, Elm_Object_Select_Mode mode)
 {
    ELM_CHECK_WIDTYPE(obj, widtype);
    Widget_Data *wd = elm_widget_data_get(obj);
    if (!wd) return;
-   wd->always_select = always_select;
+   if (mode >= ELM_OBJECT_SELECT_MODE_MAX)
+     return;
+   if (wd->select_mode != mode)
+     wd->select_mode = mode;
 }
 
-EAPI Eina_Bool
-elm_list_always_select_mode_get(const Evas_Object *obj)
+EAPI Elm_Object_Select_Mode
+elm_list_select_mode_get(const Evas_Object *obj)
 {
-   ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
+   ELM_CHECK_WIDTYPE(obj, widtype) ELM_OBJECT_SELECT_MODE_MAX;
    Widget_Data *wd = elm_widget_data_get(obj);
-   if (!wd) return EINA_FALSE;
-   return wd->always_select;
+   if (!wd) return ELM_OBJECT_SELECT_MODE_MAX;
+   return wd->select_mode;
 }
 
 EAPI void
@@ -1909,6 +1933,7 @@ elm_list_item_show(Elm_Object_Item *it)
    Evas_Coord bx, by, bw, bh;
    Evas_Coord x, y, w, h;
 
+   evas_smart_objects_calculate(evas_object_evas_get(wd->box));
    evas_object_geometry_get(wd->box, &bx, &by, &bw, &bh);
    evas_object_geometry_get(VIEW(it), &x, &y, &w, &h);
    x -= bx;
@@ -1925,6 +1950,7 @@ elm_list_item_bring_in(Elm_Object_Item *it)
    Evas_Coord bx, by, bw, bh;
    Evas_Coord x, y, w, h;
 
+   evas_smart_objects_calculate(evas_object_evas_get(wd->box));
    evas_object_geometry_get(wd->box, &bx, &by, &bw, &bh);
    evas_object_geometry_get(VIEW(it), &x, &y, &w, &h);
    x -= bx;
@@ -1957,172 +1983,22 @@ elm_list_item_next(const Elm_Object_Item *it)
    else return NULL;
 }
 
-EINA_DEPRECATED EAPI void
-elm_list_item_del(Elm_Object_Item *it)
-{
-   elm_object_item_del(it);
-}
-
-EINA_DEPRECATED EAPI Evas_Object *
-elm_list_item_base_get(const Elm_Object_Item *it)
-{
-   return elm_list_item_object_get(it);
-}
-
-EINA_DEPRECATED EAPI void
-elm_list_item_disabled_set(Elm_Object_Item *it, Eina_Bool disabled)
-{
-   elm_object_item_disabled_set(it, disabled);
-}
-
-EINA_DEPRECATED EAPI Eina_Bool
-elm_list_item_disabled_get(const Elm_Object_Item *it)
-{
-   return elm_object_item_disabled_get(it);
-}
-
-EINA_DEPRECATED EAPI void
-elm_list_item_del_cb_set(Elm_Object_Item *it, Evas_Smart_Cb func)
-{
-   elm_object_item_del_cb_set(it, func);
-}
-
-EINA_DEPRECATED EAPI void *
-elm_list_item_data_get(const Elm_Object_Item *it)
-{
-   return elm_object_item_data_get(it);
-}
-
-EINA_DEPRECATED EAPI Evas_Object *
-elm_list_item_icon_get(const Elm_Object_Item *it)
-{
-   return _item_content_get(it, NULL);
-}
-
-EINA_DEPRECATED EAPI void
-elm_list_item_icon_set(Elm_Object_Item *it, Evas_Object *icon)
-{
-   _item_content_set(it, NULL, icon);
-}
-
-EINA_DEPRECATED EAPI Evas_Object *
-elm_list_item_end_get(const Elm_Object_Item *it)
-{
-   return _item_content_get(it, "end");
-}
-
-EINA_DEPRECATED EAPI void
-elm_list_item_end_set(Elm_Object_Item *it, Evas_Object *end)
-{
-   _item_content_set(it, "end", end);
-}
-
-EINA_DEPRECATED EAPI const char *
-elm_list_item_label_get(const Elm_Object_Item *it)
-{
-   return _item_text_get(it, NULL);
-}
-
-EINA_DEPRECATED EAPI void
-elm_list_item_label_set(Elm_Object_Item *it, const char *text)
-{
-   _item_text_set(it, NULL, text);
-}
-
-EINA_DEPRECATED EAPI void
-elm_list_item_tooltip_text_set(Elm_Object_Item *it, const char *text)
-{
-   ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
-   elm_widget_item_tooltip_text_set(it, text);
-}
-
-EINA_DEPRECATED EAPI void
-elm_list_item_tooltip_content_cb_set(Elm_Object_Item *it, Elm_Tooltip_Item_Content_Cb func, const void *data, Evas_Smart_Cb del_cb)
-{
-   ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
-   elm_widget_item_tooltip_content_cb_set(it, func, data, del_cb);
-}
-
-EINA_DEPRECATED EAPI void
-elm_list_item_tooltip_unset(Elm_Object_Item *it)
-{
-   ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
-   elm_widget_item_tooltip_unset(it);
-}
-
-EINA_DEPRECATED EAPI Eina_Bool
-elm_list_item_tooltip_window_mode_set(Elm_Object_Item *it, Eina_Bool disable)
-{
-   ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, EINA_FALSE);
-   return elm_widget_item_tooltip_window_mode_set(it, disable);
-}
-
-EINA_DEPRECATED EAPI Eina_Bool
-elm_list_item_tooltip_window_mode_get(const Elm_Object_Item *it)
-{
-   ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, EINA_FALSE);
-   return elm_widget_item_tooltip_window_mode_get(it);
-}
-
-EINA_DEPRECATED EAPI void
-elm_list_item_tooltip_style_set(Elm_Object_Item *it, const char *style)
-{
-   ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
-   elm_widget_item_tooltip_style_set(it, style);
-}
-
-EINA_DEPRECATED EAPI const char *
-elm_list_item_tooltip_style_get(const Elm_Object_Item *it)
-{
-   ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
-   return elm_widget_item_tooltip_style_get(it);
-}
-
-EINA_DEPRECATED EAPI void
-elm_list_item_cursor_set(Elm_Object_Item *it, const char *cursor)
-{
-   ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
-   elm_widget_item_cursor_set(it, cursor);
-}
-
-EINA_DEPRECATED EAPI const char *
-elm_list_item_cursor_get(const Elm_Object_Item *it)
-{
-   ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
-   return elm_widget_item_cursor_get(it);
-}
-
-EINA_DEPRECATED EAPI void
-elm_list_item_cursor_unset(Elm_Object_Item *it)
-{
-   ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
-   elm_widget_item_cursor_unset(it);
-}
-
-EINA_DEPRECATED EAPI void
-elm_list_item_cursor_style_set(Elm_Object_Item *it, const char *style)
-{
-   ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
-   elm_widget_item_cursor_style_set(it, style);
-}
-
-EINA_DEPRECATED EAPI const char *
-elm_list_item_cursor_style_get(const Elm_Object_Item *it)
-{
-   ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
-   return elm_widget_item_cursor_style_get(it);
-}
-
-EINA_DEPRECATED EAPI void
-elm_list_item_cursor_engine_only_set(Elm_Object_Item *it, Eina_Bool engine_only)
+EAPI Elm_Object_Item *
+elm_list_first_item_get(const Evas_Object *obj)
 {
-   ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
-   elm_widget_item_cursor_engine_only_set(it, engine_only);
+   ELM_CHECK_WIDTYPE(obj, widtype) NULL;
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return NULL;
+   if (!wd->items) return NULL;
+   return eina_list_data_get(wd->items);
 }
 
-EINA_DEPRECATED EAPI Eina_Bool
-elm_list_item_cursor_engine_only_get(const Elm_Object_Item *it)
+EAPI Elm_Object_Item *
+elm_list_last_item_get(const Evas_Object *obj)
 {
-   ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, EINA_FALSE);
-   return elm_widget_item_cursor_engine_only_get(it);
+   ELM_CHECK_WIDTYPE(obj, widtype) NULL;
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return NULL;
+   if (!wd->items) return NULL;
+   return eina_list_data_get(eina_list_last(wd->items));
 }