Merge "[datetime_input_ctxpopup.c] Default AM/PM strings are added to display, incase...
[framework/uifw/elementary.git] / src / lib / elm_scroller.c
index b25faa7..49959b2 100644 (file)
@@ -1,5 +1,6 @@
 #include <Elementary.h>
 #include "elm_priv.h"
+#include "els_scroller.h"
 
 typedef struct _Widget_Data Widget_Data;
 
@@ -53,7 +54,6 @@ _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type ty
    if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
    Evas_Event_Key_Down *ev = event_info;
    Widget_Data *wd = elm_widget_data_get(obj);
-
    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;
@@ -68,149 +68,53 @@ _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type ty
    Evas_Coord v_h = 0;
    Evas_Coord page_x = 0;
    Evas_Coord page_y = 0;
-   Evas_Coord c_x = 0;
-   Evas_Coord c_y = 0;
 
    elm_smart_scroller_child_pos_get(wd->scr, &x, &y);
    elm_smart_scroller_step_size_get(wd->scr, &step_x, &step_y);
    elm_smart_scroller_page_size_get(wd->scr, &page_x, &page_y);
    elm_smart_scroller_child_viewport_size_get(wd->scr, &v_w, &v_h);
-   evas_object_geometry_get(wd->content, &c_x, &c_y, &max_x, &max_y);
+   elm_scroller_child_size_get(obj, &max_x, &max_y);
 
    if ((!strcmp(ev->keyname, "Left")) ||
-       (!strcmp(ev->keyname, "KP_Left")) ||
-       (!strcmp(ev->keyname, "Right")) ||
-       (!strcmp(ev->keyname, "KP_Right")) ||
-       (!strcmp(ev->keyname, "Up"))  ||
-       (!strcmp(ev->keyname, "KP_Up")) ||
-       (!strcmp(ev->keyname, "Down")) ||
-       (!strcmp(ev->keyname, "KP_Down")))
-     {
-        Evas_Object *current_focus = NULL;
-        Evas_Object *new_focus = NULL;
-        Eina_List *can_focus_list = NULL;
-        Evas_Coord f_x = 0;
-        Evas_Coord f_y = 0;
-        Evas_Coord f_w = 0;
-        Evas_Coord f_h = 0;
-
-        current_focus = elm_widget_focused_object_get(obj);
-        evas_object_geometry_get(current_focus, &f_x, &f_y, &f_w, &f_h);
-        can_focus_list = elm_widget_can_focus_child_list_get(obj);
-        if ((current_focus == obj) ||
-            (!ELM_RECTS_INTERSECT(x, y, v_w, v_h,
-                                  (f_x - c_x), (f_y - c_y), f_w, f_h)))
-          {
-             Evas_Object *cur;
-             Eina_List *l;
-             double weight = 0.0;
-
-             EINA_LIST_FOREACH(can_focus_list, l, cur)
-               {
-                  double cur_weight = 0.0;
-                  evas_object_geometry_get(cur, &f_x, &f_y, &f_w, &f_h);
-                  if (ELM_RECTS_INTERSECT(x, y, v_w, v_h,
-                                          (f_x - c_x), (f_y - c_y), f_w, f_h))
-                    {
-                       if ((f_x - c_x) > x)
-                         cur_weight += ((f_x - c_x) - x) * ((f_x - c_x) - x);
-                       if ((f_y - c_y) > y)
-                         cur_weight += ((f_y - c_y) - y) * ((f_y - c_y) - y);
-                       if (cur_weight == 0.0)
-                         {
-                            elm_widget_focus_steal(cur);
-                            return EINA_TRUE;
-                         }
-                       cur_weight = 1.0 / cur_weight;
-                       if (cur_weight > weight)
-                         {
-                            new_focus = cur;
-                            weight = cur_weight;
-                         }
-                    }
-               }
-             if (new_focus)
-               {
-                  elm_widget_focus_steal(new_focus);
-                  return EINA_TRUE;
-               }
-          }
-        else
-          {
-             Evas_Object *tmp = NULL;
-             Elm_Focus_Direction dir = ELM_FOCUS_PREVIOUS;
-             void *(*list_data_get) (const Eina_List *list);
-             list_data_get = eina_list_data_get;
-
-             if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")))
-               dir = ELM_FOCUS_LEFT;
-             else if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")))
-               dir = ELM_FOCUS_RIGHT;
-             else if ((!strcmp(ev->keyname, "Up"))  || (!strcmp(ev->keyname, "KP_Up")))
-               dir = ELM_FOCUS_UP;
-             else if ((!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
-               dir = ELM_FOCUS_DOWN;
-
-             if (elm_widget_focus_list_next_get(obj, can_focus_list, list_data_get, dir, &tmp))
-               new_focus = tmp;
-
-             if (new_focus)
-               {
-                  Evas_Coord l_x = 0;
-                  Evas_Coord l_y = 0;
-                  Evas_Coord l_w = 0;
-                  Evas_Coord l_h = 0;
-
-                  evas_object_geometry_get(new_focus, &f_x, &f_y, &f_w, &f_h);
-                  l_x = f_x - c_x - step_x;
-                  l_y = f_y - c_y - step_y;
-                  l_w = f_w + (step_x * 2);
-                  l_h = f_h + (step_y * 2);
-                  if (ELM_RECTS_INTERSECT(x, y, v_w, v_h, l_x, l_y, l_w, l_h))
-                      {
-                       elm_widget_focus_steal(new_focus);
-                       return EINA_TRUE;
-                    }
-               }
-          }
-     }
-
-   if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")))
+       ((!strcmp(ev->keyname, "KP_Left")) && (!ev->string)))
      {
-        if (x <= 0) return EINA_FALSE;
         x -= step_x;
      }
-   else if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")))
+   else if ((!strcmp(ev->keyname, "Right")) ||
+            ((!strcmp(ev->keyname, "KP_Right")) && (!ev->string)))
      {
-        if (x >= (max_x - v_w)) return EINA_FALSE;
         x += step_x;
      }
-   else if ((!strcmp(ev->keyname, "Up"))  || (!strcmp(ev->keyname, "KP_Up")))
+   else if ((!strcmp(ev->keyname, "Up")) ||
+            ((!strcmp(ev->keyname, "KP_Up")) && (!ev->string)))
      {
-        if (y == 0) return EINA_FALSE;
         y -= step_y;
      }
-   else if ((!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
+   else if ((!strcmp(ev->keyname, "Down")) ||
+            ((!strcmp(ev->keyname, "KP_Down")) && (!ev->string)))
      {
-        if (y >= (max_y - v_h)) return EINA_FALSE;
         y += step_y;
      }
-   else if ((!strcmp(ev->keyname, "Home")) || (!strcmp(ev->keyname, "KP_Home")))
+   else if ((!strcmp(ev->keyname, "Home")) ||
+            ((!strcmp(ev->keyname, "KP_Home")) && (!ev->string)))
      {
         y = 0;
      }
-   else if ((!strcmp(ev->keyname, "End")) || (!strcmp(ev->keyname, "KP_End")))
+   else if ((!strcmp(ev->keyname, "End")) ||
+            ((!strcmp(ev->keyname, "KP_End")) && (!ev->string)))
      {
         y = max_y - v_h;
      }
-   else if ((!strcmp(ev->keyname, "Prior")) || (!strcmp(ev->keyname, "KP_Prior")))
+   else if ((!strcmp(ev->keyname, "Prior")) ||
+            ((!strcmp(ev->keyname, "KP_Prior")) && (!ev->string)))
      {
         if (page_y < 0)
           y -= -(page_y * v_h) / 100;
         else
           y -= page_y;
      }
-   else if ((!strcmp(ev->keyname, "Next")) || (!strcmp(ev->keyname, "KP_Next")))
+   else if ((!strcmp(ev->keyname, "Next")) ||
+            ((!strcmp(ev->keyname, "KP_Next")) && (!ev->string)))
      {
         if (page_y < 0)
           y += -(page_y * v_h) / 100;
@@ -231,12 +135,12 @@ _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
    if (!wd) return;
    if (elm_widget_focus_get(obj))
      {
-        edje_object_signal_emit(wd->scr, "elm,action,focus", "elm");
+        edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr), "elm,action,focus", "elm");
         evas_object_focus_set(wd->scr, EINA_TRUE);
      }
    else
      {
-        edje_object_signal_emit(wd->scr, "elm,action,unfocus", "elm");
+        edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr), "elm,action,unfocus", "elm");
         evas_object_focus_set(wd->scr, EINA_FALSE);
      }
 }
@@ -296,8 +200,11 @@ _elm_scroller_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, E
    cur = wd->content;
 
    /* Try Focus cycle in subitem */
-   if ((elm_widget_can_focus_get(cur)) || (elm_widget_child_can_focus_get(cur)))
-     return elm_widget_focus_next_get(cur, dir, next);
+   if (elm_widget_focus_get(obj))
+     {
+        if ((elm_widget_can_focus_get(cur)) || (elm_widget_child_can_focus_get(cur)))
+          return elm_widget_focus_next_get(cur, dir, next);
+     }
 
    /* Return */
    *next = (Evas_Object *)obj;
@@ -354,7 +261,7 @@ static void
 _sizing_eval(Evas_Object *obj)
 {
    Widget_Data *wd = elm_widget_data_get(obj);
-   Evas_Coord  vw, vh, minw = 0, minh = 0, maxw = 0, maxh = 0, w, h, vmw, vmh;
+   Evas_Coord  vw = 0, vh = 0, minw = 0, minh = 0, maxw = 0, maxh = 0, w, h, vmw, vmh;
    double xw = 0.0, yw = 0.0;
 
    if (!wd) return;
@@ -517,6 +424,71 @@ _scroll_drag_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UN
    evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_STOP, NULL);
 }
 
+Evas_Object *
+_elm_scroller_edje_object_get(Evas_Object *obj)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype) NULL;
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return NULL;
+   return elm_smart_scroller_edje_object_get(wd->scr);
+}
+
+static void
+_content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype);
+   Widget_Data *wd;
+   if (part && strcmp(part, "default")) return;
+   wd = elm_widget_data_get(obj);
+   if (!wd) return;
+   if (wd->content == content) return;
+   if (wd->content) evas_object_del(wd->content);
+   wd->content = content;
+   if (content)
+     {
+        elm_widget_on_show_region_hook_set(content, _show_region_hook, obj);
+        elm_widget_sub_object_add(obj, content);
+        if (wd->scr)
+          elm_smart_scroller_child_set(wd->scr, content);
+        evas_object_event_callback_add(content,
+                                       EVAS_CALLBACK_CHANGED_SIZE_HINTS,
+                                       _changed_size_hints, obj);
+     }
+   _sizing_eval(obj);
+}
+
+static Evas_Object *
+_content_get_hook(const Evas_Object *obj, const char *part)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype) NULL;
+   Widget_Data *wd;
+   if (part && strcmp(part, "default")) return NULL;
+   wd = elm_widget_data_get(obj);
+   if (!wd) return NULL;
+   return wd->content;
+}
+
+static Evas_Object *
+_content_unset_hook(Evas_Object *obj, const char *part)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype) NULL;
+   Widget_Data *wd;
+   Evas_Object *content;
+   if (part && strcmp(part, "default")) return NULL;
+   wd = elm_widget_data_get(obj);
+   if (!wd) return NULL;
+   if (!wd->content) return NULL;
+   content = wd->content;
+   elm_widget_sub_object_del(obj, wd->content);
+   evas_object_event_callback_del_full(wd->content,
+                                       EVAS_CALLBACK_CHANGED_SIZE_HINTS,
+                                       _changed_size_hints, obj);
+   edje_object_part_unswallow(elm_smart_scroller_edje_object_get(wd->scr),
+                              wd->content);
+   wd->content = NULL;
+   return content;
+}
+
 EAPI Evas_Object *
 elm_scroller_add(Evas_Object *parent)
 {
@@ -541,6 +513,9 @@ elm_scroller_add(Evas_Object *parent)
    elm_widget_can_focus_set(obj, EINA_TRUE);
    elm_widget_event_hook_set(obj, _event_hook);
    elm_widget_focus_region_hook_set(obj, _focus_region_hook);
+   elm_widget_content_set_hook_set(obj, _content_set_hook);
+   elm_widget_content_get_hook_set(obj, _content_get_hook);
+   elm_widget_content_unset_hook_set(obj, _content_unset_hook);
 
    wd->widget_name = eina_stringshare_add("scroller");
    wd->widget_base = eina_stringshare_add("base");
@@ -581,60 +556,6 @@ elm_scroller_add(Evas_Object *parent)
    return obj;
 }
 
-Evas_Object *
-_elm_scroller_edje_object_get(Evas_Object *obj)
-{
-   ELM_CHECK_WIDTYPE(obj, widtype) NULL;
-   Widget_Data *wd = elm_widget_data_get(obj);
-   if (!wd) return NULL;
-   return elm_smart_scroller_edje_object_get(wd->scr);
-}
-
-EAPI void
-elm_scroller_content_set(Evas_Object *obj, Evas_Object *content)
-{
-   ELM_CHECK_WIDTYPE(obj, widtype);
-   Widget_Data *wd = elm_widget_data_get(obj);
-   if (!wd) return;
-   if (wd->content == content) return;
-   if (wd->content) evas_object_del(wd->content);
-   wd->content = content;
-   if (content)
-     {
-        elm_widget_on_show_region_hook_set(content, _show_region_hook, obj);
-        elm_widget_sub_object_add(obj, content);
-        if (wd->scr)
-          elm_smart_scroller_child_set(wd->scr, content);
-        evas_object_event_callback_add(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
-                                       _changed_size_hints, obj);
-     }
-   _sizing_eval(obj);
-}
-
-EAPI Evas_Object *
-elm_scroller_content_get(const Evas_Object *obj)
-{
-   ELM_CHECK_WIDTYPE(obj, widtype) NULL;
-   Widget_Data *wd = elm_widget_data_get(obj);
-   if (!wd) return NULL;
-   return wd->content;
-}
-
-EAPI Evas_Object *
-elm_scroller_content_unset(Evas_Object *obj)
-{
-   ELM_CHECK_WIDTYPE(obj, widtype) NULL;
-   Widget_Data *wd = elm_widget_data_get(obj);
-   Evas_Object *content;
-   if (!wd) return NULL;
-   if (!wd->content) return NULL;
-   content = wd->content;
-   elm_widget_sub_object_del(obj, wd->content);
-   edje_object_part_unswallow(wd->scr, wd->content);
-   wd->content = NULL;
-   return content;
-}
-
 EAPI void
 elm_scroller_custom_widget_base_theme_set(Evas_Object *obj, const char *widget, const char *base)
 {
@@ -673,15 +594,11 @@ elm_scroller_policy_set(Evas_Object *obj, Elm_Scroller_Policy policy_h, Elm_Scro
 {
    ELM_CHECK_WIDTYPE(obj, widtype);
    Widget_Data *wd = elm_widget_data_get(obj);
-   const Elm_Scroller_Policy map[3] =
-     {
-        ELM_SMART_SCROLLER_POLICY_AUTO,
-        ELM_SMART_SCROLLER_POLICY_ON,
-        ELM_SMART_SCROLLER_POLICY_OFF
-     };
    if ((!wd) || (!wd->scr)) return;
-   if ((policy_h >= 3) || (policy_v >= 3)) return;
-   elm_smart_scroller_policy_set(wd->scr, map[policy_h], map[policy_v]);
+   if ((policy_h >= ELM_SCROLLER_POLICY_LAST) ||
+       (policy_v >= ELM_SCROLLER_POLICY_LAST))
+     return;
+   elm_smart_scroller_policy_set(wd->scr, policy_h, policy_v);
 }
 
 EAPI void
@@ -759,6 +676,46 @@ elm_scroller_page_size_set(Evas_Object *obj, Evas_Coord h_pagesize, Evas_Coord v
 }
 
 EAPI void
+elm_scroller_current_page_get(const Evas_Object *obj, int *h_pagenumber, int *v_pagenumber)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype);
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return;
+   if (wd->scr)
+     elm_smart_scroller_current_page_get(wd->scr, h_pagenumber, v_pagenumber);
+}
+
+EAPI void
+elm_scroller_last_page_get(const Evas_Object *obj, int *h_pagenumber, int *v_pagenumber)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype);
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return;
+   if (wd->scr)
+     elm_smart_scroller_last_page_get(wd->scr, h_pagenumber, v_pagenumber);
+}
+
+EAPI void
+elm_scroller_page_show(Evas_Object *obj, int h_pagenumber, int v_pagenumber)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype);
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return;
+   if (wd->scr)
+     elm_smart_scroller_page_show(wd->scr, h_pagenumber, v_pagenumber);
+}
+
+EAPI void
+elm_scroller_page_bring_in(Evas_Object *obj, int h_pagenumber, int v_pagenumber)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype);
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return;
+   if (wd->scr)
+     elm_smart_scroller_page_bring_in(wd->scr, h_pagenumber, v_pagenumber);
+}
+
+EAPI void
 elm_scroller_region_bring_in(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
 {
    ELM_CHECK_WIDTYPE(obj, widtype);
@@ -786,3 +743,23 @@ elm_scroller_propagate_events_get(const Evas_Object *obj)
 
    return evas_object_propagate_events_get(wd->scr);
 }
+
+EAPI void
+elm_scroller_gravity_set(Evas_Object *obj, double x, double y)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype);
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return;
+
+   elm_smart_scroller_gravity_set(wd->scr, x, y);
+}
+
+EAPI void
+elm_scroller_gravity_get(const Evas_Object *obj, double *x, double *y)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype);
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return;
+
+   elm_smart_scroller_gravity_get(wd->scr, x, y);
+}