Merge branch 'master' into svn_merge
[framework/uifw/elementary.git] / src / lib / elm_pager.c
old mode 100755 (executable)
new mode 100644 (file)
index 4c47da6..0583593
@@ -3,12 +3,11 @@
 
 /**
  * @defgroup Pager Pager
- * @ingroup Elementary
  *
  * The pager is an object that allows flipping (with animation) between 1 or
- * more ?\9cpages??of objects, much like a stack of windows within the window.
+ * more “pages” of objects, much like a stack of windows within the window.
  *
- * Objects can be pushed or popped from he stack or deleted as normal.
+ * Objects can be pushed or popped from the stack or deleted as normal.
  * Pushes and pops will animate (and a pop will delete the object once the
  * animation is finished). Any object in the pager can be promoted to the top
  * (from its current stacking position) as well. Objects are pushed to the
  * needed and is not the top item, just delete it as normal. You can query
  * which objects are the top and bottom with elm_pager_content_bottom_get()
  * and elm_pager_content_top_get().
+ *
+ * Signals that you can add callbacks for are:
+ *
+ * "hide,finished" - when the previous page is hided
+ *
  */
 
 typedef struct _Widget_Data Widget_Data;
@@ -29,6 +33,7 @@ struct _Widget_Data
    Eina_List *stack;
    Item *top, *oldtop;
    Evas_Object *rect, *clip;
+   Eina_Bool disable_animation: 1;
 };
 
 struct _Item
@@ -40,10 +45,25 @@ struct _Item
 
 static const char *widtype = NULL;
 static void _del_hook(Evas_Object *obj);
+static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
 static void _theme_hook(Evas_Object *obj);
 static void _sizing_eval(Evas_Object *obj);
-static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
-static void _sub_del(void *data, Evas_Object *obj, void *event_info);
+static void _changed_size_hints(void *data,
+                                Evas *e,
+                                Evas_Object *obj,
+                                void *event_info);
+static void _content_del(void *data,
+                         Evas *e,
+                         Evas_Object *obj,
+                         void *event_info);
+static Eina_List *_item_get(Evas_Object *obj, Evas_Object *content);
+
+static const char SIG_HIDE_FINISHED[] = "hide,finished";
+
+static const Evas_Smart_Cb_Description _signals[] = {
+   {SIG_HIDE_FINISHED, ""},
+   {NULL, NULL}
+};
 
 static void
 _del_hook(Evas_Object *obj)
@@ -54,18 +74,67 @@ _del_hook(Evas_Object *obj)
 }
 
 static void
+_mirrored_set(Evas_Object *obj, Eina_Bool rtl)
+{
+   Widget_Data *wd = elm_widget_data_get(obj);
+   Eina_List *l;
+   Item *it;
+   if (!wd) return;
+   EINA_LIST_FOREACH(wd->stack, l, it)
+      edje_object_mirrored_set(it->base, rtl);
+}
+
+static void
 _theme_hook(Evas_Object *obj)
 {
    Widget_Data *wd = elm_widget_data_get(obj);
    Eina_List *l;
    Item *it;
    if (!wd) return;
+   _elm_widget_mirrored_reload(obj);
+   _mirrored_set(obj, elm_widget_mirrored_get(obj));
    EINA_LIST_FOREACH(wd->stack, l, it)
-     edje_object_scale_set(it->base, elm_widget_scale_get(obj) * 
-                           _elm_config->scale);
+     {
+        _elm_theme_object_set(obj, it->base,  "pager", "base",
+                              elm_widget_style_get(obj));
+        edje_object_scale_set(it->base, elm_widget_scale_get(obj) *
+                              _elm_config->scale);
+     }
    _sizing_eval(obj);
 }
 
+static Eina_List *
+_item_get(Evas_Object *obj, Evas_Object *content)
+{
+   Widget_Data *wd = elm_widget_data_get(obj);
+   Item *it;
+   Eina_List *l;
+   if (!wd) return NULL;
+
+   EINA_LIST_FOREACH(wd->stack, l, it)
+     {
+        if (it->content == content)
+          return l;
+     }
+
+   return NULL;
+}
+
+static Eina_Bool
+_elm_pager_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
+{
+   Widget_Data *wd = elm_widget_data_get(obj);
+   Evas_Object *cur;
+
+   if ((!wd) || (!wd->top))
+     return EINA_FALSE;
+
+   cur = wd->top->content;
+
+   /* Try Focus cycle in subitem */
+   return elm_widget_focus_next_get(cur, dir, next);
+}
+
 static void
 _sizing_eval(Evas_Object *obj)
 {
@@ -76,8 +145,8 @@ _sizing_eval(Evas_Object *obj)
    if (!wd) return;
    EINA_LIST_FOREACH(wd->stack, l, it)
      {
-       if (it->minw > minw) minw = it->minw;
-       if (it->minh > minh) minh = it->minh;
+        if (it->minw > minw) minw = it->minw;
+        if (it->minh > minh) minh = it->minh;
      }
    evas_object_size_hint_min_set(obj, minw, minh);
    evas_object_size_hint_max_set(obj, -1, -1);
@@ -100,53 +169,68 @@ static void
 _eval_top(Evas_Object *obj)
 {
    Widget_Data *wd = elm_widget_data_get(obj);
-   Eina_Bool animate=EINA_TRUE;
+   Eina_Bool show_noanimate = EINA_TRUE;
    Item *ittop;
    if (!wd) return;
    if (!wd->stack) return;
    ittop = eina_list_last(wd->stack)->data;
    if (ittop != wd->top)
      {
-       Evas_Object *o;
-       const char *onshow, *onhide;
-
-       if (wd->top)
-         {
-            o = wd->top->base;
-            if (wd->top->popme)
-               edje_object_signal_emit(o, "elm,action,pop", "elm");
-            else
-               edje_object_signal_emit(o, "elm,action,hide", "elm");
-            onhide = edje_object_data_get(o, "onhide");
-            if (onhide)
-              {
-                 if (!strcmp(onhide, "raise")) evas_object_raise(o);
-                 else if (!strcmp(onhide, "lower")) evas_object_lower(o);
-              }
-         }
-       else
-         {
-            animate = EINA_FALSE;
-         }
-       wd->top = ittop;
-       o = wd->top->base;
-       evas_object_show(o);
-       wd->oldtop = wd->top;
-       wd->top = ittop;
-       o = wd->top->base;
-       evas_object_show(o);
-       if (!animate)
-               edje_object_signal_emit(o, "elm,action,show,noanimate", "elm");
-       else if (wd->oldtop && wd->oldtop->popme)
-           edje_object_signal_emit(o, "elm,action,show", "elm");
-       else
-           edje_object_signal_emit(o, "elm,action,push", "elm");
-       onshow = edje_object_data_get(o, "onshow");
-       if (onshow)
-         {
-            if (!strcmp(onshow, "raise")) evas_object_raise(o);
-            else if (!strcmp(onshow, "lower")) evas_object_lower(o);
-         }
+        Evas_Object *o;
+        const char *onshow, *onhide;
+
+        if (wd->top)
+          {
+             o = wd->top->base;
+             if(wd->disable_animation)
+               {
+                  edje_object_signal_emit(o, "elm,action,hide,noanimate", "elm");
+                  if (wd->top->popme)
+                    wd->stack = eina_list_remove(wd->stack, wd->top);
+               }
+             else if (wd->top->popme)
+               {
+                  edje_object_signal_emit(o, "elm,action,pop", "elm");
+                  wd->stack = eina_list_remove(wd->stack, wd->top);
+               }
+             else
+               edje_object_signal_emit(o, "elm,action,hide", "elm");
+             onhide = edje_object_data_get(o, "onhide");
+             if (onhide)
+               {
+                  if (!strcmp(onhide, "raise")) evas_object_raise(o);
+                  else if (!strcmp(onhide, "lower")) evas_object_lower(o);
+               }
+          }
+        else
+          {
+             show_noanimate = EINA_FALSE;
+          }
+        wd->oldtop = wd->top;
+        wd->top = ittop;
+        o = wd->top->base;
+        evas_object_show(o);
+        if ((!show_noanimate)||(wd->disable_animation))
+          {
+             edje_object_signal_emit(o, "elm,action,show,noanimate", "elm");
+          }
+        else if (wd->oldtop)
+          {
+             if (elm_object_focus_get(wd->oldtop->content))
+               elm_object_focus(wd->top->content);
+             if (wd->oldtop->popme)
+               edje_object_signal_emit(o, "elm,action,show", "elm");
+             else
+               edje_object_signal_emit(o, "elm,action,push", "elm");
+          }
+        else
+          edje_object_signal_emit(o, "elm,action,push", "elm");
+        onshow = edje_object_data_get(o, "onshow");
+        if (onshow)
+          {
+             if (!strcmp(onshow, "raise")) evas_object_raise(o);
+             else if (!strcmp(onshow, "lower")) evas_object_lower(o);
+          }
      }
 }
 
@@ -164,31 +248,26 @@ _move(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSE
 }
 
 static void
-_sub_del(void *data, Evas_Object *obj __UNUSED__, void *event_info)
+_content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
 {
    Widget_Data *wd = elm_widget_data_get(data);
-   Evas_Object *sub = event_info;
    Eina_List *l;
    Item *it;
    if (!wd) return;
-   EINA_LIST_FOREACH(wd->stack, l, it)
-     {
-       if (it->content == sub)
-         {
-            wd->stack = eina_list_remove_list(wd->stack, l);
-            evas_object_event_callback_del_full
-               (sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, it);
-            evas_object_del(it->base);
-            _eval_top(it->obj);
-            free(it);
-            return;
-         }
-     }
+   l = _item_get(data, obj);
+   if (!l) return;
+   it = l->data;
+   wd->stack = eina_list_remove_list(wd->stack, l);
+   evas_object_event_callback_del_full
+      (obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, it);
+   evas_object_del(it->base);
+   _eval_top(data);
+   free(it);
 }
 
 static void
 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
-{   
+{
    Widget_Data *wd = elm_widget_data_get(data);
    Evas_Coord w, h;
    Eina_List *l;
@@ -203,12 +282,30 @@ _signal_hide_finished(void *data, Evas_Object *obj __UNUSED__, const char *emiss
 {
    Item *it = data;
    Evas_Object *obj2 = it->obj;
-   evas_object_hide(it->base);
-   edje_object_signal_emit(it->base, "elm,action,reset", "elm");
-   evas_object_smart_callback_call(obj2, "hide,finished", it->content);
-   edje_object_message_signal_process(it->base);
-   if (it->popme) evas_object_del(it->content);
-   _sizing_eval(obj2);
+   Evas_Object *content = it->content;
+
+   if (it->popme)
+     {
+        evas_object_del(it->base);
+        evas_object_event_callback_del_full(content,
+                                            EVAS_CALLBACK_CHANGED_SIZE_HINTS,
+                                            _changed_size_hints,
+                                            it);
+        evas_object_event_callback_del(content,
+                                       EVAS_CALLBACK_DEL,
+                                       _content_del);
+        evas_object_del(content);
+        free(it);
+     }
+   else
+     {
+        evas_object_hide(it->base);
+        edje_object_signal_emit(it->base, "elm,action,reset", "elm");
+        edje_object_message_signal_process(it->base);
+        evas_object_hide(content);
+     }
+    evas_object_smart_callback_call(obj2, SIG_HIDE_FINISHED, content);
+    _sizing_eval(obj2);
 }
 
 /**
@@ -226,15 +323,16 @@ elm_pager_add(Evas_Object *parent)
    Evas *e;
    Widget_Data *wd;
 
-   wd = ELM_NEW(Widget_Data);
-   e = evas_object_evas_get(parent);
-   obj = elm_widget_add(e);
+   ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
+
    ELM_SET_WIDTYPE(widtype, "pager");
    elm_widget_type_set(obj, "pager");
    elm_widget_sub_object_add(parent, obj);
    elm_widget_data_set(obj, wd);
    elm_widget_del_hook_set(obj, _del_hook);
    elm_widget_theme_hook_set(obj, _theme_hook);
+   elm_widget_focus_next_hook_set(obj, _elm_pager_focus_next_hook);
+   elm_widget_can_focus_set(obj, EINA_FALSE);
 
    wd->clip = evas_object_rectangle_add(e);
    elm_widget_resize_object_set(obj, wd->clip);
@@ -242,14 +340,15 @@ elm_pager_add(Evas_Object *parent)
 
    wd->rect = evas_object_rectangle_add(e);
    elm_widget_sub_object_add(obj, wd->rect);
-   evas_object_color_set(wd->rect, 255, 255, 255, 0); 
+   evas_object_color_set(wd->rect, 255, 255, 255, 0);
    evas_object_clip_set(wd->rect, wd->clip);
 
    evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _move, obj);
    evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, obj);
 
-   evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
+   evas_object_smart_callbacks_descriptions_set(obj, _signals);
 
+   _mirrored_set(obj, elm_widget_mirrored_get(obj));
    _sizing_eval(obj);
    return obj;
 }
@@ -264,15 +363,20 @@ elm_pager_add(Evas_Object *parent)
  * @param content The object to push
  *
  * @ingroup Pager
+ * @warning It will be failed if the content exists on the stack already.
  */
 EAPI void
 elm_pager_content_push(Evas_Object *obj, Evas_Object *content)
 {
    ELM_CHECK_WIDTYPE(obj, widtype);
    Widget_Data *wd = elm_widget_data_get(obj);
-   Item *it = ELM_NEW(Item);
    Evas_Coord x, y, w, h;
-   if (!wd) return;
+   Item *it;
+
+   if ((!wd) || (!content)) return;
+   if (_item_get(obj, content)) return;
+
+   it = ELM_NEW(Item);
    if (!it) return;
    it->obj = obj;
    it->content = content;
@@ -284,14 +388,27 @@ elm_pager_content_push(Evas_Object *obj, Evas_Object *content)
    evas_object_clip_set(it->base, wd->clip);
    elm_widget_sub_object_add(obj, it->base);
    elm_widget_sub_object_add(obj, it->content);
-   _elm_theme_object_set(obj, it->base,  "pager", "base", elm_widget_style_get(obj));
-   edje_object_signal_callback_add(it->base, "elm,action,hide,finished", "", 
-                                   _signal_hide_finished, it);
+   _elm_theme_object_set(obj,
+                         it->base,
+                         "pager",
+                         "base",
+                         elm_widget_style_get(obj));
+   edje_object_signal_callback_add(it->base,
+                                   "elm,action,hide,finished",
+                                   "",
+                                   _signal_hide_finished,
+                                   it);
    evas_object_event_callback_add(it->content,
                                   EVAS_CALLBACK_CHANGED_SIZE_HINTS,
-                                  _changed_size_hints, it);
+                                  _changed_size_hints,
+                                  it);
+   evas_object_event_callback_add(it->content,
+                                  EVAS_CALLBACK_DEL,
+                                  _content_del,
+                                  obj);
    edje_object_part_swallow(it->base, "elm.swallow.content", it->content);
    edje_object_size_min_calc(it->base, &it->minw, &it->minh);
+   evas_object_data_set(it->base, "_elm_leaveme", obj);
    evas_object_show(it->content);
    wd->stack = eina_list_append(wd->stack, it);
    _eval_top(obj);
@@ -323,30 +440,32 @@ elm_pager_content_pop(Evas_Object *obj)
    ll = eina_list_last(wd->stack);
    if (ll)
      {
-       ll = ll->prev;
-       if (!ll)
-         {
-            Evas_Object *o;
-            const char *onhide;
-
-            wd->top = it;
-            o = wd->top->base;
-            edje_object_signal_emit(o, "elm,action,pop", "elm");
-            onhide = edje_object_data_get(o, "onhide");
-            if (onhide)
-              {
-                 if (!strcmp(onhide, "raise")) evas_object_raise(o);
-                 else if (!strcmp(onhide, "lower")) evas_object_lower(o);
-              }
-            wd->top = NULL;
-         }
-       else
-         {
-            it = ll->data;
-            elm_pager_content_promote(obj, it->content);
-         }
+        ll = ll->prev;
+        if (!ll)
+          {
+             Evas_Object *o;
+             const char *onhide;
+
+             wd->top = it;
+             o = wd->top->base;
+             edje_object_signal_emit(o, "elm,action,pop", "elm");
+             wd->stack = eina_list_remove(wd->stack, it);
+             onhide = edje_object_data_get(o, "onhide");
+             if (onhide)
+               {
+                  if (!strcmp(onhide, "raise")) evas_object_raise(o);
+                  else if (!strcmp(onhide, "lower")) evas_object_lower(o);
+               }
+             wd->top = NULL;
+          }
+        else
+          {
+             it = ll->data;
+             elm_pager_content_promote(obj, it->content);
+          }
      }
 }
+
 static void
 _del_job(void *data)
 {
@@ -379,20 +498,21 @@ elm_pager_to_content_pop(Evas_Object *obj, Evas_Object *content)
    ll = eina_list_last(wd->stack);
    if (ll)
      {
-       while(ll)
-                       {
-                               it = ll->data;
-                               if(it->content != content)
-                                       {
-                                               wd->stack = eina_list_remove_list(wd->stack, ll);
-                                               ecore_job_add(_del_job, it->content);
-                                       }
-                               else
-                                       break;
-                               
-                               ll = ll->prev;
-                       }
-      }
+        while(ll)
+          {
+             it = ll->data;
+             if(it->content != content)
+               {
+                  wd->stack = eina_list_remove_list(wd->stack, ll);
+                  ecore_job_add(_del_job, it->content);
+                  it->content = NULL;
+               }
+             else
+               break;
+             
+             ll = ll->prev;
+          }
+     }
    _eval_top(it->obj);
 }
 
@@ -416,16 +536,13 @@ elm_pager_content_promote(Evas_Object *obj, Evas_Object *content)
    Eina_List *l;
    Item *it;
    if (!wd) return;
-   EINA_LIST_FOREACH(wd->stack, l, it)
-     {
-       if (it->content == content)
-         {
-            wd->stack = eina_list_remove_list(wd->stack, l);
-            wd->stack = eina_list_append(wd->stack, it);
-            _eval_top(obj);
-            return;
-         }
-     }
+   l = _item_get(obj, content);
+   if (!l) return;
+
+   it = l->data;
+   wd->stack = eina_list_remove_list(wd->stack, l);
+   wd->stack = eina_list_append(wd->stack, it);
+   _eval_top(obj);
 }
 
 /**
@@ -461,10 +578,23 @@ elm_pager_content_top_get(const Evas_Object *obj)
 {
    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
    Widget_Data *wd = elm_widget_data_get(obj);
-   Item *it;
    if (!wd) return NULL;
-   if (!wd->stack) return NULL;
-   it = eina_list_last(wd->stack)->data;
-   return it->content;
+   if (!wd->top) return NULL;
+   return wd->top->content;
 }
 
+/**
+ * This disables content animation on push/pop.
+ *
+ * @param obj The pager object
+ * @param disable  if EINA_TRUE animation is disabled.
+ *
+ * @ingroup Pager
+ */
+EAPI void
+elm_pager_animation_disabled_set(Evas_Object *obj, Eina_Bool disable)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype)NULL;
+   Widget_Data *wd = elm_widget_data_get(obj);
+   wd->disable_animation = disable;
+}