elm genlist/list/gengrid: Removed deprecated signal "clicked". Use
[framework/uifw/elementary.git] / src / lib / elm_gengrid.c
index f7e0c43..8589638 100644 (file)
  typedef struct _Pan         Pan;
 
 #define PRELOAD 1
+#define REORDER_EFFECT_TIME 0.5
 
  struct _Elm_Gengrid_Item
 {
    Evas_Object                  *spacer;
    const Elm_Gengrid_Item_Class *gic;
    Ecore_Timer                  *long_timer;
+   Ecore_Animator               *item_moving_effect_timer;
    Widget_Data                  *wd;
    Eina_List                    *labels, *icons, *states, *icon_objs;
    struct
         const void   *data;
      } func;
 
-   Evas_Coord x, y, dx, dy;
-   int        relcount;
-   int        walking;
+   Evas_Coord   x, y, dx, dy, ox, oy, tx, ty, rx, ry;
+   unsigned int moving_effect_start_time;
+   int          relcount;
+   int          walking;
 
    struct
      {
    Eina_Bool   disabled : 1;
    Eina_Bool   selected : 1;
    Eina_Bool   hilighted : 1;
+   Eina_Bool   moving : 1;
 };
 
 struct _Widget_Data
@@ -197,7 +201,7 @@ struct _Widget_Data
    Elm_Gengrid_Item *last_selected_item, *reorder_item;
    double            align_x, align_y;
 
-   Evas_Coord        pan_x, pan_y;
+   Evas_Coord        pan_x, pan_y, old_pan_x, old_pan_y;
    Evas_Coord        item_width, item_height; /* Each item size */
    Evas_Coord        minw, minh; /* Total obj size */
    Evas_Coord        reorder_item_x, reorder_item_y;
@@ -217,6 +221,7 @@ struct _Widget_Data
    Eina_Bool         v_bounce : 1;
    Eina_Bool         reorder_mode : 1;
    Eina_Bool         reorder_item_changed : 1;
+   Eina_Bool         move_effect_enabled : 1;
 };
 
 #define ELM_GENGRID_ITEM_FROM_INLIST(item) \
@@ -268,6 +273,7 @@ static const char SIG_DRAG[] = "drag";
 static const char SIG_SCROLL[] = "scroll";
 static const char SIG_SCROLL_DRAG_START[] = "scroll,drag,start";
 static const char SIG_SCROLL_DRAG_STOP[] = "scroll,drag,stop";
+static const char SIG_MOVED[] = "moved";
 
 static const Evas_Smart_Cb_Description _signals[] = {
        {SIG_CLICKED_DOUBLE, ""},
@@ -285,10 +291,12 @@ static const Evas_Smart_Cb_Description _signals[] = {
        {SIG_SCROLL, ""},
        {SIG_SCROLL_DRAG_START, ""},
        {SIG_SCROLL_DRAG_STOP, ""},
+       {SIG_MOVED, ""},
        {NULL, NULL}
 };
 
-
+static Eina_Compare_Cb _elm_gengrid_item_compare_cb;
+static Eina_Compare_Cb _elm_gengrid_item_compare_data_cb;
 
 static Eina_Bool
 _event_hook(Evas_Object       *obj,
@@ -464,7 +472,6 @@ _event_hook(Evas_Object       *obj,
      {
         item = elm_gengrid_selected_item_get(obj);
         evas_object_smart_callback_call(item->wd->self, SIG_CLICKED_DOUBLE, item);
-        evas_object_smart_callback_call(item->wd->self, "clicked", item); // will be removed
      }
    else return EINA_FALSE;
 
@@ -956,7 +963,7 @@ _mouse_up(void            *data,
         if (item->wd->calc_job) ecore_job_del(item->wd->calc_job);
           item->wd->calc_job = ecore_job_add(_calc_job, item->wd);
 
-        evas_object_smart_callback_call(item->wd->self, "moved", item->wd->reorder_item);
+        evas_object_smart_callback_call(item->wd->self, SIG_MOVED, item->wd->reorder_item);
         item->wd->reorder_item = NULL;
         elm_smart_scroller_hold_set(item->wd->scr, EINA_FALSE);
         elm_smart_scroller_bounce_allow_set(item->wd->scr, item->wd->h_bounce, item->wd->v_bounce);
@@ -1166,6 +1173,45 @@ _item_unrealize(Elm_Gengrid_Item *item)
    item->want_unrealize = EINA_FALSE;
 }
 
+static Eina_Bool
+_reorder_item_moving_effect_timer_cb(void *data)
+{
+   Elm_Gengrid_Item *item = data;
+   double time, t;
+   Evas_Coord dx, dy;
+
+   time = REORDER_EFFECT_TIME;
+   t = ((0.0 > (t = ecore_loop_time_get()-item->moving_effect_start_time)) ? 0.0 : t);
+   dx = ((item->tx - item->ox) / 10) * _elm_config->scale;
+   dy = ((item->ty - item->oy) / 10) * _elm_config->scale;
+
+   if (t <= time)
+     {
+        item->rx += (1 * sin((t / time) * (M_PI / 2)) * dx);
+        item->ry += (1 * sin((t / time) * (M_PI / 2)) * dy);
+     }
+   else
+     {
+        item->rx += dx;
+        item->ry += dy;
+     }
+
+   if ((((dx > 0) && (item->rx >= item->tx)) || ((dx <= 0) && (item->rx <= item->tx))) &&
+       (((dy > 0) && (item->ry >= item->ty)) || ((dy <= 0) && (item->ry <= item->ty))))
+     {
+        evas_object_move(item->base.view, item->tx, item->ty);
+        evas_object_resize(item->base.view, item->wd->item_width, item->wd->item_height);
+        item->moving = EINA_FALSE;
+        item->item_moving_effect_timer = NULL;
+        return ECORE_CALLBACK_CANCEL;
+     }
+
+   evas_object_move(item->base.view, item->rx, item->ry);
+   evas_object_resize(item->base.view, item->wd->item_width, item->wd->item_height);
+
+   return ECORE_CALLBACK_RENEW;
+}
+
 static void
 _item_place(Elm_Gengrid_Item *item,
             Evas_Coord        cx,
@@ -1251,6 +1297,13 @@ _item_place(Elm_Gengrid_Item *item,
           evas_object_smart_callback_call(item->wd->self, SIG_REALIZED, item);
         if ((item->wd->reorder_mode) && (item->wd->reorder_item))
           {
+             if (item->moving) return;
+
+             if (!item->wd->move_effect_enabled)
+               {
+                  item->ox = x;
+                  item->oy = y;
+               }
              if (item->wd->reorder_item == item)
                {
                   evas_object_move(item->base.view,
@@ -1261,6 +1314,26 @@ _item_place(Elm_Gengrid_Item *item,
                }
              else
                {
+                  if (item->wd->move_effect_enabled)
+                    {
+                       if ((item->ox != x) || (item->oy != y))
+                         {
+                            if (((item->wd->old_pan_x == item->wd->pan_x) && (item->wd->old_pan_y == item->wd->pan_y)) ||
+                                ((item->wd->old_pan_x != item->wd->pan_x) && !(item->ox - item->wd->pan_x + item->wd->old_pan_x == x)) ||
+                                ((item->wd->old_pan_y != item->wd->pan_y) && !(item->oy - item->wd->pan_y + item->wd->old_pan_y == y)))
+                              {
+                                 item->tx = x;
+                                 item->ty = y;
+                                 item->rx = item->ox;
+                                 item->ry = item->oy;
+                                 item->moving = EINA_TRUE;
+                                 item->moving_effect_start_time = ecore_loop_time_get();
+                                 item->item_moving_effect_timer = ecore_animator_add(_reorder_item_moving_effect_timer_cb, item);
+                                 return;
+                              }
+                         }
+                    }
+
                   if (ELM_RECTS_INTERSECT(item->wd->reorder_item_x, item->wd->reorder_item_y,
                                           item->wd->item_width, item->wd->item_height,
                                           x+(item->wd->item_width/2), y+(item->wd->item_height/2),
@@ -1291,7 +1364,7 @@ _item_place(Elm_Gengrid_Item *item,
                                                                        EINA_INLIST_GET(item));
 
                        item->wd->reorder_item_changed = EINA_TRUE;
-
+                       item->wd->move_effect_enabled = EINA_TRUE;
                        if (item->wd->calc_job) ecore_job_del(item->wd->calc_job);
                          item->wd->calc_job = ecore_job_add(_calc_job, item->wd);
 
@@ -1373,6 +1446,7 @@ call:
      evas_object_smart_callback_call(item->wd->self, SIG_SELECTED, item);
    item->walking--;
    item->wd->walking--;
+   item->wd->last_selected_item = item;
    if ((item->wd->clear_me) && (!item->wd->walking))
      elm_gengrid_clear(item->base.widget);
    else
@@ -1380,7 +1454,6 @@ call:
         if ((!item->walking) && (item->delete_me))
           if (!item->relcount) _item_del(item);
      }
-   item->wd->last_selected_item = item;
 }
 
 static void
@@ -1569,6 +1642,16 @@ _pan_calculate(Evas_Object *obj)
              if (!cx) cy++;
           }
      }
+
+   if ((sd->wd->reorder_mode) && (sd->wd->reorder_item))
+     {
+        if (!sd->wd->reorder_item_changed)
+          {
+             sd->wd->old_pan_x = sd->wd->pan_x;
+             sd->wd->old_pan_y = sd->wd->pan_y;
+          }
+        sd->wd->move_effect_enabled = EINA_FALSE;
+     }
    evas_object_smart_callback_call(sd->wd->self, SIG_CHANGED, NULL);
 }
 
@@ -1647,6 +1730,24 @@ _scr_scroll(void            *data,
    evas_object_smart_callback_call(data, SIG_SCROLL, NULL);
 }
 
+static int
+_elm_gengrid_item_compare_data(const void *data, const void *data1)
+{
+   const Elm_Gengrid_Item *item = data;
+   const Elm_Gengrid_Item *item1 = data1;
+
+   return _elm_gengrid_item_compare_data_cb(item->base.data, item1->base.data);
+}
+
+static int
+_elm_gengrid_item_compare(const void *data, const void *data1)
+{
+   Elm_Gengrid_Item *item, *item1;
+   item = ELM_GENGRID_ITEM_FROM_INLIST(data);
+   item1 = ELM_GENGRID_ITEM_FROM_INLIST(data1);
+   return _elm_gengrid_item_compare_cb(item, item1);
+}
+
 /**
  * Add a new Gengrid object.
  *
@@ -2013,6 +2114,44 @@ elm_gengrid_item_insert_after(Evas_Object                  *obj,
    return item;
 }
 
+EAPI Elm_Gengrid_Item *
+elm_gengrid_item_direct_sorted_insert(Evas_Object                  *obj,
+                                     const Elm_Gengrid_Item_Class *gic,
+                                     const void                   *data,
+                                     Eina_Compare_Cb               comp,
+                                     Evas_Smart_Cb                 func,
+                                     const void                   *func_data)
+{
+   Elm_Gengrid_Item *item;
+   ELM_CHECK_WIDTYPE(obj, widtype) NULL;
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return NULL;
+
+   item = _item_create(wd, gic, data, func, func_data);
+   if (!item) return NULL;
+
+   _elm_gengrid_item_compare_cb = comp;
+   wd->items = eina_inlist_sorted_insert(wd->items, EINA_INLIST_GET(item),
+                                         _elm_gengrid_item_compare);
+   if (wd->calc_job) ecore_job_del(wd->calc_job);
+   wd->calc_job = ecore_job_add(_calc_job, wd);
+
+   return item;
+}
+
+EAPI Elm_Gengrid_Item *
+elm_gengrid_item_sorted_insert(Evas_Object                  *obj,
+                               const Elm_Gengrid_Item_Class *gic,
+                               const void                   *data,
+                               Eina_Compare_Cb               comp,
+                               Evas_Smart_Cb                 func,
+                               const void                   *func_data)
+{
+   _elm_gengrid_item_compare_data_cb = comp;
+
+   return elm_gengrid_item_direct_sorted_insert(obj, gic, data, _elm_gengrid_item_compare_data, func, func_data);
+}
+
 /**
  * Remove an item from the Gengrid.
  *
@@ -2234,6 +2373,25 @@ elm_gengrid_item_data_set(Elm_Gengrid_Item *item,
    elm_gengrid_item_update(item);
 }
 
+EAPI const Elm_Gengrid_Item_Class *
+elm_gengrid_item_item_class_get(const Elm_Gengrid_Item *item)
+{
+   ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
+   if (item->delete_me) return NULL;
+   return item->gic;
+}
+
+EAPI void
+elm_gengrid_item_item_class_set(Elm_Gengrid_Item *item,
+                                const Elm_Gengrid_Item_Class *gic)
+{
+   ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
+   EINA_SAFETY_ON_NULL_RETURN(gic);
+   if (item->delete_me) return;
+   item->gic = gic;
+   elm_gengrid_item_update(item);
+}
+
 /**
  * Get the item's coordinates.
  *
@@ -2451,7 +2609,7 @@ _elm_gengrid_item_label_create(void        *data,
    if (!label)
      return NULL;
    elm_object_style_set(label, "tooltip");
-   elm_label_label_set(label, data);
+   elm_object_text_set(label, data);
    return label;
 }