Merge "[copy&paste] add interface for OSP"
[framework/uifw/elementary.git] / src / lib / els_pan.c
index 9e0ae1c..4e02b3d 100644 (file)
@@ -12,6 +12,8 @@ struct _Smart_Data
    Evas_Object *child_obj;
    Evas_Coord   x, y, w, h;
    Evas_Coord   child_w, child_h, px, py;
+   double       gravity_x, gravity_y;
+   Evas_Coord   prev_cw, prev_ch, delta_posx, delta_posy;
 };
 
 /* local subsystem functions */
@@ -48,30 +50,30 @@ _elm_smart_pan_child_set(Evas_Object *obj, Evas_Object *child)
    if (child == sd->child_obj) return;
    if (sd->child_obj)
      {
-       evas_object_clip_unset(sd->child_obj);
-       evas_object_smart_member_del(sd->child_obj);
+        evas_object_clip_unset(sd->child_obj);
+        evas_object_smart_member_del(sd->child_obj);
         evas_object_event_callback_del_full(sd->child_obj, EVAS_CALLBACK_FREE, _smart_child_del_hook, sd);
-       evas_object_event_callback_del_full(sd->child_obj, EVAS_CALLBACK_RESIZE, _smart_child_resize_hook, sd);
-       sd->child_obj = NULL;
+        evas_object_event_callback_del_full(sd->child_obj, EVAS_CALLBACK_RESIZE, _smart_child_resize_hook, sd);
+        sd->child_obj = NULL;
      }
    if (child)
      {
-       Evas_Coord w, h;
-       int r, g, b, a;
-
-       sd->child_obj = child;
-       evas_object_smart_member_add(sd->child_obj, sd->smart_obj);
-       evas_object_geometry_get(sd->child_obj, NULL, NULL, &w, &h);
-       sd->child_w = w;
-       sd->child_h = h;
-       evas_object_event_callback_add(child, EVAS_CALLBACK_FREE, _smart_child_del_hook, sd);
-       evas_object_event_callback_add(child, EVAS_CALLBACK_RESIZE, _smart_child_resize_hook, sd);
-       evas_object_color_get(sd->smart_obj, &r, &g, &b, &a);
-       evas_object_color_set(sd->child_obj, r, g, b, a);
-       evas_object_clip_set(sd->child_obj, evas_object_clip_get(sd->smart_obj));
-       if (evas_object_visible_get(sd->smart_obj)) evas_object_show(sd->child_obj);
-       else evas_object_hide(sd->child_obj);
-       _smart_reconfigure(sd);
+        Evas_Coord w, h;
+        int r, g, b, a;
+
+        sd->child_obj = child;
+        evas_object_smart_member_add(sd->child_obj, sd->smart_obj);
+        evas_object_geometry_get(sd->child_obj, NULL, NULL, &w, &h);
+        sd->child_w = w;
+        sd->child_h = h;
+        evas_object_event_callback_add(child, EVAS_CALLBACK_FREE, _smart_child_del_hook, sd);
+        evas_object_event_callback_add(child, EVAS_CALLBACK_RESIZE, _smart_child_resize_hook, sd);
+        evas_object_color_get(sd->smart_obj, &r, &g, &b, &a);
+        evas_object_color_set(sd->child_obj, r, g, b, a);
+        evas_object_clip_set(sd->child_obj, evas_object_clip_get(sd->smart_obj));
+        if (evas_object_visible_get(sd->smart_obj)) evas_object_show(sd->child_obj);
+        else evas_object_hide(sd->child_obj);
+        _smart_reconfigure(sd);
      }
    evas_object_smart_callback_call(sd->smart_obj, "changed", NULL);
 }
@@ -87,10 +89,10 @@ void
 _elm_smart_pan_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
 {
    API_ENTRY return;
-//   if (x > (sd->child_w - sd->w)) x = sd->child_w - sd->w;
-//   if (y > (sd->child_h - sd->h)) y = sd->child_h - sd->h;
-//   if (x < 0) x = 0;
-//   if (y < 0) y = 0;
+   //   if (x > (sd->child_w - sd->w)) x = sd->child_w - sd->w;
+   //   if (y > (sd->child_h - sd->h)) y = sd->child_h - sd->h;
+   //   if (x < 0) x = 0;
+   //   if (y < 0) y = 0;
    if ((x == sd->px) && (y == sd->py)) return;
    sd->px = x;
    sd->py = y;
@@ -112,13 +114,13 @@ _elm_smart_pan_max_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
    API_ENTRY return;
    if (x)
      {
-       if (sd->w < sd->child_w) *x = sd->child_w - sd->w;
-       else *x = 0;
+        if (sd->w < sd->child_w) *x = sd->child_w - sd->w;
+        else *x = 0;
      }
    if (y)
      {
-       if (sd->h < sd->child_h) *y = sd->child_h - sd->h;
-       else *y = 0;
+        if (sd->h < sd->child_h) *y = sd->child_h - sd->h;
+        else *y = 0;
      }
 }
 
@@ -140,6 +142,26 @@ _elm_smart_pan_child_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
    if (h) *h = sd->child_h;
 }
 
+void
+_elm_smart_pan_gravity_set(Evas_Object *obj, double x, double y)
+{
+   API_ENTRY return;
+   sd->gravity_x = x;
+   sd->gravity_y = y;
+   sd->prev_cw = sd->child_w;
+   sd->prev_ch = sd->child_h;
+   sd->delta_posx = 0;
+   sd->delta_posy = 0;
+}
+
+void
+_elm_smart_pan_gravity_get(Evas_Object *obj, double *x, double *y)
+{
+   API_ENTRY return;
+   if (x) *x = sd->gravity_x;
+   if (y) *y = sd->gravity_y;
+}
+
 /* local subsystem functions */
 static void
 _smart_child_del_hook(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
@@ -161,9 +183,9 @@ _smart_child_resize_hook(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUS
    evas_object_geometry_get(sd->child_obj, NULL, NULL, &w, &h);
    if ((w != sd->child_w) || (h != sd->child_h))
      {
-       sd->child_w = w;
-       sd->child_h = h;
-       _smart_reconfigure(sd);
+        sd->child_w = w;
+        sd->child_h = h;
+        _smart_reconfigure(sd);
      }
    evas_object_smart_callback_call(sd->smart_obj, "changed", NULL);
 }
@@ -171,7 +193,25 @@ _smart_child_resize_hook(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUS
 static void
 _smart_reconfigure(Smart_Data *sd)
 {
-   evas_object_move(sd->child_obj, sd->x - sd->px, sd->y - sd->py);
+   if (sd->gravity_x || sd->gravity_y)
+     {
+        if ((!sd->px) && (!sd->py))
+          {
+             sd->px = sd->delta_posx*sd->gravity_x;
+             sd->py = sd->delta_posy*sd->gravity_y;
+          }
+        sd->delta_posx += sd->child_w - sd->prev_cw;
+        sd->prev_cw = sd->child_w;
+        sd->delta_posy += sd->child_h - sd->prev_ch;
+        sd->prev_ch = sd->child_h;
+
+        evas_object_move(sd->child_obj, sd->x - sd->px, sd->y - sd->py);
+        sd->px = sd->delta_posx*sd->gravity_x;
+        sd->py = sd->delta_posy*sd->gravity_y;
+
+     }
+   else
+     evas_object_move(sd->child_obj, sd->x - sd->px, sd->y - sd->py);
 }
 
 static void
@@ -186,6 +226,8 @@ _smart_add(Evas_Object *obj)
    sd->y = 0;
    sd->w = 0;
    sd->h = 0;
+   sd->gravity_x = 0.0;
+   sd->gravity_y = 0.0;
    evas_object_smart_data_set(obj, sd);
 }
 
@@ -263,28 +305,28 @@ _smart_init(void)
 {
    if (_smart) return;
      {
-       static const Evas_Smart_Class sc =
-         {
-            SMART_NAME,
-              EVAS_SMART_CLASS_VERSION,
-              _smart_add,
-              _smart_del,
-              _smart_move,
-              _smart_resize,
-              _smart_show,
-              _smart_hide,
-              _smart_color_set,
-              _smart_clip_set,
-              _smart_clip_unset,
-              NULL,
-              NULL,
-              NULL,
-              NULL,
-              NULL,
-              NULL,
-              NULL
-         };
-       _smart = evas_smart_class_new(&sc);
+        static const Evas_Smart_Class sc =
+          {
+             SMART_NAME,
+             EVAS_SMART_CLASS_VERSION,
+             _smart_add,
+             _smart_del,
+             _smart_move,
+             _smart_resize,
+             _smart_show,
+             _smart_hide,
+             _smart_color_set,
+             _smart_clip_set,
+             _smart_clip_unset,
+             NULL,
+             NULL,
+             NULL,
+             NULL,
+             NULL,
+             NULL,
+             NULL
+          };
+        _smart = evas_smart_class_new(&sc);
      }
 }