[Slideshow] Applying Open source patch r72492 to fix Switching in slideshow with...
[framework/uifw/elementary.git] / src / lib / elm_slideshow.c
index 7009b83..68549a4 100644 (file)
@@ -33,10 +33,11 @@ struct _Widget_Data
    double timeout;
    Eina_Bool loop:1;
 
-   struct {
+   struct
+     {
         const char *current;
         Eina_List *list; //list of const char *
-   } layout;
+     } layout;
 };
 
 static const char *widtype = NULL;
@@ -69,13 +70,15 @@ _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type ty
    if (!wd) return EINA_FALSE;
    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
    if (elm_widget_disabled_get(obj)) return EINA_FALSE;
-   if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")))
+   if ((!strcmp(ev->keyname, "Left")) ||
+       ((!strcmp(ev->keyname, "KP_Left")) && (!ev->string)))
      {
         elm_slideshow_previous(obj);
         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
         return EINA_TRUE;
      }
-   if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")))
+   if ((!strcmp(ev->keyname, "Right")) ||
+       ((!strcmp(ev->keyname, "KP_Right")) && (!ev->string)))
      {
         elm_slideshow_next(obj);
         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
@@ -220,6 +223,7 @@ _item_realize(Elm_Slideshow_Item *item)
         evas_object_smart_member_add(VIEW(item), obj);
         item->l_built = eina_list_append(NULL, item);
         wd->items_built = eina_list_merge(wd->items_built, item->l_built);
+        //FIXME: item could be showed by obj
         evas_object_hide(VIEW(item));
      }
    else if (item->l_built)
@@ -252,6 +256,7 @@ _item_realize(Elm_Slideshow_Item *item)
                        _item_next->l_built = eina_list_append(NULL, _item_next);
                        wd->items_built = eina_list_merge(wd->items_built,
                                                          _item_next->l_built);
+                       //FIXME: _item_next could be showed by obj later
                        evas_object_hide(VIEW(_item_next));
                     }
                   else if (_item_next && _item_next->l_built)
@@ -283,6 +288,7 @@ _item_realize(Elm_Slideshow_Item *item)
                        _item_prev->l_built = eina_list_append(NULL, _item_prev);
                        wd->items_built = eina_list_merge(wd->items_built,
                                                          _item_prev->l_built);
+                       //FIXME: _item_prev could be showed by obj later
                        evas_object_hide(VIEW(_item_prev));
                     }
                   else if (_item_prev && _item_prev->l_built)
@@ -348,6 +354,39 @@ _timer_cb(void *data)
    return ECORE_CALLBACK_CANCEL;
 }
 
+static Eina_Bool
+_item_del_pre_hook(Elm_Object_Item *it)
+{
+   Elm_Slideshow_Item *item = (Elm_Slideshow_Item *)it;
+   Widget_Data *wd = elm_widget_data_get(WIDGET(item));
+   if (!wd) return EINA_FALSE;
+
+   if (wd->previous == item) wd->previous = NULL;
+   if (wd->current == item)
+     {
+        Eina_List *l = eina_list_data_find_list(wd->items, item);
+        Eina_List *l2 = eina_list_next(l);
+        wd->current = NULL;
+        if (!l2)
+          {
+             l2 = eina_list_prev(l);
+             if (l2)
+               elm_slideshow_item_show(eina_list_data_get(l2));
+
+          }
+        else
+          elm_slideshow_item_show(eina_list_data_get(l2));
+     }
+
+   wd->items = eina_list_remove_list(wd->items, item->l);
+   wd->items_built = eina_list_remove_list(wd->items_built, item->l_built);
+
+   if ((VIEW(item)) && (item->itc->func.del))
+     item->itc->func.del(elm_widget_item_data_get(item), VIEW(item));
+
+   return EINA_TRUE;
+}
+
 EAPI Evas_Object *
 elm_slideshow_add(Evas_Object *parent)
 {
@@ -373,11 +412,9 @@ elm_slideshow_add(Evas_Object *parent)
 
    wd->slideshow = edje_object_add(e);
    _elm_theme_object_set(obj, wd->slideshow, "slideshow", "base", "default");
-   evas_object_smart_member_add(wd->slideshow, obj);
    wd->count_item_pre_before = 2;
    wd->count_item_pre_after = 2;
    elm_widget_resize_object_set(obj, wd->slideshow);
-   evas_object_show(wd->slideshow);
 
    wd->transitions = elm_widget_stringlist_get(edje_object_data_get(wd->slideshow, "transitions"));
    if (eina_list_count(wd->transitions) > 0)
@@ -409,16 +446,16 @@ elm_slideshow_item_add(Evas_Object *obj, const Elm_Slideshow_Item_Class *itc, co
    if (!wd) return NULL;
    item = elm_widget_item_new(obj, Elm_Slideshow_Item);
    if (!item) return NULL;
-
+   elm_widget_item_del_pre_hook_set(item, _item_del_pre_hook);
    item->itc = itc;
    item->l = eina_list_append(item->l, item);
    elm_widget_item_data_set(item, data);
 
    wd->items = eina_list_merge(wd->items, item->l);
 
-   if (!wd->current) elm_slideshow_show((Elm_Object_Item *) item);
+   if (!wd->current) elm_slideshow_item_show((Elm_Object_Item *)item);
 
-   return (Elm_Object_Item *) item;
+   return (Elm_Object_Item *)item;
 }
 
 EAPI Elm_Object_Item*
@@ -431,27 +468,27 @@ elm_slideshow_item_sorted_insert(Evas_Object *obj, const Elm_Slideshow_Item_Clas
 
    item = elm_widget_item_new(obj, Elm_Slideshow_Item);
    if (!item) return NULL;
-
+   elm_widget_item_del_pre_hook_set(item, _item_del_pre_hook);
    item->itc = itc;
    item->l = eina_list_append(item->l, item);
    elm_widget_item_data_set(item, data);
 
    wd->items = eina_list_sorted_merge(wd->items, item->l, func);
 
-   if (!wd->current) elm_slideshow_show((Elm_Object_Item *) item);
+   if (!wd->current) elm_slideshow_item_show((Elm_Object_Item *)item);
 
-   return (Elm_Object_Item *) item;
+   return (Elm_Object_Item *)item;
 }
 
 EAPI void
-elm_slideshow_show(Elm_Object_Item *it)
+elm_slideshow_item_show(Elm_Object_Item *it)
 {
    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
 
    char buf[1024];
    Elm_Slideshow_Item *item, *next = NULL;
    Widget_Data *wd;
-   item = (Elm_Slideshow_Item *) it;
+   item = (Elm_Slideshow_Item *)it;
    wd = elm_widget_data_get(WIDGET(item));
    if (!wd)  return;
    if (item == wd->current) return;
@@ -460,11 +497,16 @@ elm_slideshow_show(Elm_Object_Item *it)
    _end(WIDGET(item), WIDGET(item), NULL, NULL);
 
    if (wd->timer) ecore_timer_del(wd->timer);
+   wd->timer = NULL;
    if (wd->timeout > 0.0)
      wd->timer = ecore_timer_add(wd->timeout, _timer_cb, WIDGET(item));
    _item_realize(next);
    edje_object_part_swallow(wd->slideshow, "elm.swallow.2", VIEW(next));
-   snprintf(buf, sizeof(buf), "%s,next", wd->transition);
+
+   if (!wd->transition)
+     sprintf(buf, "none,next");
+   else
+     snprintf(buf, sizeof(buf), "%s,next", wd->transition);
    edje_object_signal_emit(wd->slideshow, buf, "slideshow");
    wd->previous = wd->current;
    wd->current = next;
@@ -489,6 +531,7 @@ elm_slideshow_next(Evas_Object *obj)
    _end(obj, obj, NULL, NULL);
 
    if (wd->timer) ecore_timer_del(wd->timer);
+   wd->timer = NULL;
    if (wd->timeout > 0.0)
      wd->timer = ecore_timer_add(wd->timeout, _timer_cb, obj);
 
@@ -496,7 +539,10 @@ elm_slideshow_next(Evas_Object *obj)
 
    edje_object_part_swallow(wd->slideshow, "elm.swallow.2", VIEW(next));
 
-   snprintf(buf, sizeof(buf), "%s,next", wd->transition);
+   if (!wd->transition)
+     sprintf(buf, "none,next");
+   else
+     snprintf(buf, sizeof(buf), "%s,next", wd->transition);
    edje_object_signal_emit(wd->slideshow, buf, "slideshow");
 
    wd->previous = wd->current;
@@ -522,6 +568,7 @@ elm_slideshow_previous(Evas_Object *obj)
    _end(obj, obj, NULL, NULL);
 
    if (wd->timer) ecore_timer_del(wd->timer);
+   wd->timer = NULL;
    if (wd->timeout > 0.0)
      wd->timer = ecore_timer_add(wd->timeout, _timer_cb, obj);
 
@@ -529,7 +576,10 @@ elm_slideshow_previous(Evas_Object *obj)
 
    edje_object_part_swallow(wd->slideshow, "elm.swallow.2", VIEW(prev));
 
-   snprintf(buf, 1024, "%s,previous", wd->transition);
+   if (!wd->transition)
+     sprintf(buf, "none,previous");
+   else
+     snprintf(buf, sizeof(buf), "%s,previous", wd->transition);
    edje_object_signal_emit(wd->slideshow, buf, "slideshow");
 
    wd->previous = wd->current;
@@ -648,49 +698,10 @@ elm_slideshow_clear(Evas_Object *obj)
      {
         if (item->itc->func.del)
           item->itc->func.del(elm_widget_item_data_get(item), VIEW(item));
-        evas_object_del(VIEW(item));
-        VIEW(item) = NULL;
      }
 
    EINA_LIST_FREE(wd->items, item)
-     {
-        elm_widget_item_del(item);
-     }
-}
-
-EAPI void
-elm_slideshow_item_del(Elm_Object_Item *it)
-{
-   ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
-
-   Elm_Slideshow_Item *item = (Elm_Slideshow_Item *) it;
-   Widget_Data *wd = elm_widget_data_get(WIDGET(item));
-   if (!wd) return;
-   if (wd->previous == item) wd->previous = NULL;
-   if (wd->current == item)
-     {
-        Eina_List *l = eina_list_data_find_list(wd->items, item);
-        Eina_List *l2 = eina_list_next(l);
-        wd->current = NULL;
-        if (!l2)
-          {
-             l2 = eina_list_prev(l);
-             if (l2)
-               elm_slideshow_show(eina_list_data_get(l2));
-
-          }
-        else
-          elm_slideshow_show(eina_list_data_get(l2));
-     }
-
-   wd->items = eina_list_remove_list(wd->items, item->l);
-   wd->items_built = eina_list_remove_list(wd->items_built, item->l_built);
-
-   if ((VIEW(item)) && (item->itc->func.del))
-     item->itc->func.del(elm_widget_item_data_get(item), VIEW(item));
-   if (VIEW(item))
-     evas_object_del(VIEW(item));
-   free(item);
+     elm_widget_item_free(item);
 }
 
 EAPI const Eina_List *
@@ -718,12 +729,6 @@ elm_slideshow_item_object_get(const Elm_Object_Item * it)
    return VIEW(it);
 }
 
-EAPI void *
-elm_slideshow_item_data_get(const Elm_Object_Item * it)
-{
-   return elm_object_item_data_get(it);
-}
-
 EAPI int
 elm_slideshow_cache_before_get(const Evas_Object *obj)
 {