Get us some nice auto translation scheme
[framework/uifw/elementary.git] / src / lib / elm_genlist.c
index ba14c96..2c8ae39 100644 (file)
@@ -3,6 +3,7 @@
 #include <Elementary.h>
 #include <Elementary_Cursor.h>
 #include "elm_priv.h"
+#include "els_scroller.h"
 
 #define SWIPE_MOVES         12
 #define MAX_ITEMS_PER_BLOCK 32
@@ -15,18 +16,25 @@ typedef struct _Item_Cache  Item_Cache;
 
 struct _Widget_Data
 {
-   Evas_Object      *obj, *scr, *pan_smart;
-   Eina_Inlist      *items, *blocks;
-   Eina_List        *group_items;
-   Pan              *pan;
-   Evas_Coord        pan_x, pan_y, old_pan_y, w, h, minw, minh, realminw, prev_viewport_w;
+   Eina_Inlist_Sorted_State *state;
+   Evas_Object      *obj; /* the genlist object */
+   Evas_Object      *scr; /* a smart scroller object which is used internally in genlist */
+   Evas_Object      *pan_smart; /* "elm_genlist_pan" evas smart object. this is an extern pan of smart scroller(scr). */
+   Eina_Inlist      *items; /* inlist of all items */
+   Eina_Inlist      *blocks; /* inlist of all blocks. a block consists of a certain number of items. maximum number of items in a block is 'max_items_per_block'. */
+   Eina_List        *group_items; /* list of groups index items */
+   Pan              *pan; /* pan_smart object's smart data */
+   Evas_Coord        pan_x, pan_y, reorder_old_pan_y, w, h, minw, minh, realminw, prev_viewport_w;
    Ecore_Job        *calc_job, *update_job;
    Ecore_Idle_Enterer *queue_idle_enterer;
    Ecore_Idler        *must_recalc_idler;
    Eina_List        *queue, *selected;
-   Elm_Genlist_Item *show_item, *last_selected_item, *anchor_item, *mode_item, *reorder_it, *reorder_rel, *expanded_item;
-   Eina_Inlist      *item_cache;
-   Evas_Coord        anchor_y, reorder_start_y;
+   Elm_Genlist_Item *show_item, *anchor_item, *mode_item, *reorder_rel, *expanded_item;
+   Elm_Genlist_Item *last_selected_item; /* the last selected item. */
+   Elm_Genlist_Item *reorder_it; /* an item which is longpressed and in the moving state. */
+   Eina_Inlist      *item_cache; /* an inlist of edje object item cache. */
+   Evas_Coord        anchor_y;
+   Evas_Coord        reorder_start_y; /* reorder item's initial y coordinate in the pan. */
    Elm_List_Mode     mode;
    Ecore_Timer      *multi_timer, *scr_hold_timer;
    Ecore_Animator   *reorder_move_animator;
@@ -53,21 +61,22 @@ struct _Widget_Data
    Eina_Bool         reorder_mode : 1;
    Eina_Bool         reorder_pan_move : 1;
    Eina_Bool         auto_scroll_enabled : 1;
+   Eina_Bool         pan_resized : 1;
    struct
    {
       Evas_Coord x, y;
    } history[SWIPE_MOVES];
    int               multi_device;
    int               item_cache_count;
-   int               item_cache_max;
+   int               item_cache_max; /* maximum number of cached items */
    int               movements;
    int               walking;
    int               item_width;
    int               item_height;
    int               group_item_width;
    int               group_item_height;
-   int               max_items_per_block;
-   double            longpress_timeout;
+   int               max_items_per_block; /* maximum number of items per block */
+   double            longpress_timeout; /* longpress timeout. this value comes from _elm_config by default. this can be changed by elm_genlist_longpress_timeout_set() */
 };
 
 struct _Item_Block
@@ -211,6 +220,9 @@ static void      _signal_emit_hook(Evas_Object *obj,
                                    const char *source);
 static Eina_Bool _deselect_all_items(Widget_Data *wd);
 static void      _pan_calculate(Evas_Object *obj);
+static void      _pan_max_get(Evas_Object *obj,
+                              Evas_Coord  *x,
+                              Evas_Coord  *y);
 static void      _item_position(Elm_Genlist_Item *it,
                                 Evas_Object      *obj,
                                 Evas_Coord        it_x,
@@ -309,6 +321,7 @@ _event_hook(Evas_Object       *obj,
    if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
    Evas_Event_Key_Down *ev = event_info;
    Widget_Data *wd = elm_widget_data_get(obj);
+   Evas_Coord pan_max_x = 0, pan_max_y = 0;
    if (!wd) return EINA_FALSE;
    if (!wd->items) return EINA_FALSE;
    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
@@ -413,6 +426,11 @@ _event_hook(Evas_Object       *obj,
    else return EINA_FALSE;
 
    ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
+   _pan_max_get(wd->pan_smart, &pan_max_x, &pan_max_y);
+   if (x < 0) x = 0;
+   if (x > pan_max_x) x = pan_max_x;
+   if (y < 0) y = 0;
+   if (y > pan_max_y) y = pan_max_y;
    elm_smart_scroller_child_pos_set(wd->scr, x, y);
    return EINA_TRUE;
 }
@@ -620,6 +638,12 @@ _show_region_hook(void        *data,
 }
 
 static void
+_translate_hook(Evas_Object *obj)
+{
+   evas_object_smart_callback_call(obj, "language,changed", NULL);
+}
+
+static void
 _sizing_eval(Evas_Object *obj)
 {
    Widget_Data *wd = elm_widget_data_get(obj);
@@ -1481,6 +1505,8 @@ _mode_finished_signal_cb(void        *data,
    evas_event_freeze(te);
    it->nocache = EINA_FALSE;
    _mode_item_unrealize(it);
+   if (it->group_item)
+     evas_object_raise(it->group_item->base.view);
    snprintf(buf, sizeof(buf), "elm,state,%s,passive,finished", it->wd->mode_type);
    edje_object_signal_callback_del_full(obj, buf, "elm", _mode_finished_signal_cb, it);
    evas_event_thaw(te);
@@ -1682,6 +1708,15 @@ _item_label_hook(Elm_Genlist_Item *it, const char *part)
 }
 
 static void
+_item_del_hook(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
+{
+   Elm_Genlist_Item *it = event_info;
+   if (!it) return;
+   if (it->wd->last_selected_item == it)
+     it->wd->last_selected_item = NULL;
+}
+
+static void
 _item_label_realize(Elm_Genlist_Item *it,
                     Evas_Object *target,
                     Eina_List **source)
@@ -2342,7 +2377,7 @@ _calc_job(void *data)
    Evas_Coord minw = -1, minh = 0, y = 0, ow;
    int in = 0;
    double t0, t;
-   Eina_Bool minw_change = EINA_FALSE, changed = EINA_FALSE;
+   Eina_Bool minw_change = EINA_FALSE;
    Eina_Bool did_must_recalc = EINA_FALSE;
    if (!wd) return;
 
@@ -2363,10 +2398,9 @@ _calc_job(void *data)
           {
              if (itb->realized) _item_block_unrealize(itb);
           }
-        if ((itb->changed) || (changed) ||
-            ((itb->must_recalc) && (!did_must_recalc)))
+        if ((itb->changed) || ((itb->must_recalc) && (!did_must_recalc)))
           {
-             if ((changed) || (itb->must_recalc))
+             if (itb->must_recalc)
                {
                   Eina_List *l;
                   Elm_Genlist_Item *it;
@@ -2679,11 +2713,18 @@ _pan_resize(Evas_Object *obj,
    if ((ow == w) && (oh == h)) return;
    if ((sd->wd->height_for_width) && (ow != w))
      {
+        /* fix me later */
         if (sd->resize_job) ecore_job_del(sd->resize_job);
         sd->resize_job = ecore_job_add(_pan_resize_job, sd);
      }
+   sd->wd->pan_resized = EINA_TRUE;
+   evas_object_smart_changed(obj);
+   if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
+   sd->wd->calc_job = NULL;
+/* OLD
    if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
    sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
+ */
 }
 
 static void
@@ -2698,6 +2739,13 @@ _pan_calculate(Evas_Object *obj)
 
    if (!sd) return;
    evas_event_freeze(evas_object_evas_get(obj));
+   
+   if (sd->wd->pan_resized)
+     {
+        _calc_job(sd->wd);
+        sd->wd->pan_resized = EINA_FALSE;
+     }
+   
    evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
    evas_output_viewport_get(evas_object_evas_get(obj), &cvx, &cvy, &cvw, &cvh);
    EINA_LIST_FOREACH(sd->wd->group_items, l, git)
@@ -2726,11 +2774,11 @@ _pan_calculate(Evas_Object *obj)
       _group_items_recalc(sd->wd);
    if ((sd->wd->reorder_mode) && (sd->wd->reorder_it))
      {
-        if (sd->wd->pan_y != sd->wd->old_pan_y)
+        if (sd->wd->pan_y != sd->wd->reorder_old_pan_y)
            sd->wd->reorder_pan_move = EINA_TRUE;
         else sd->wd->reorder_pan_move = EINA_FALSE;
         evas_object_raise(sd->wd->reorder_it->base.view);
-        sd->wd->old_pan_y = sd->wd->pan_y;
+        sd->wd->reorder_old_pan_y = sd->wd->pan_y;
         sd->wd->start_time = ecore_loop_time_get();
      }
    _item_auto_scroll(sd->wd);
@@ -2963,6 +3011,8 @@ _item_mode_set(Elm_Genlist_Item *it)
 
    evas_event_freeze(evas_object_evas_get(it->wd->obj));
    _mode_item_realize(it);
+   if (it->group_item)
+     evas_object_raise(it->group_item->base.view);
    _item_position(it, it->mode_view, it->scrl_x, it->scrl_y);
    evas_event_thaw(evas_object_evas_get(it->wd->obj));
    evas_event_thaw_eval(evas_object_evas_get(it->wd->obj));
@@ -3050,6 +3100,7 @@ elm_genlist_add(Evas_Object *parent)
    elm_widget_can_focus_set(obj, EINA_TRUE);
    elm_widget_event_hook_set(obj, _event_hook);
    elm_widget_on_show_region_hook_set(obj, _show_region_hook, obj);
+   elm_widget_translate_hook_set(obj, _translate_hook);
 
    wd->scr = elm_smart_scroller_add(e);
    elm_smart_scroller_widget_set(wd->scr, obj);
@@ -3123,6 +3174,7 @@ _item_new(Widget_Data                  *wd,
    it->mouse_cursor = NULL;
    it->expanded_depth = 0;
    elm_widget_item_text_get_hook_set(it, _item_label_hook);
+   elm_widget_item_del_cb_set(it, _item_del_hook);
 
    if (it->parent)
      {
@@ -3652,11 +3704,16 @@ elm_genlist_item_direct_sorted_insert(Evas_Object                  *obj,
      }
    else
      {
+        if (!wd->state)
+          {
+             wd->state = eina_inlist_sorted_state_new();
+          }
+
         if (flags & ELM_GENLIST_ITEM_GROUP)
           wd->group_items = eina_list_append(wd->group_items, it);
 
-        wd->items = eina_inlist_sorted_insert(wd->items, EINA_INLIST_GET(it),
-                                              _elm_genlist_item_compare);
+        wd->items = eina_inlist_sorted_state_insert(wd->items, EINA_INLIST_GET(it),
+                                                    _elm_genlist_item_compare, wd->state);
 
         if (EINA_INLIST_GET(it)->next)
           {
@@ -3703,6 +3760,11 @@ elm_genlist_clear(Evas_Object *obj)
    ELM_CHECK_WIDTYPE(obj, widtype);
    Widget_Data *wd = elm_widget_data_get(obj);
    if (!wd) return;
+   if (wd->state)
+     {
+        eina_inlist_sorted_state_free(wd->state);
+        wd->state = NULL;
+     }
    if (wd->walking > 0)
      {
         Elm_Genlist_Item *it;
@@ -3780,7 +3842,7 @@ elm_genlist_clear(Evas_Object *obj)
    wd->show_item = NULL;
    wd->pan_x = 0;
    wd->pan_y = 0;
-   wd->old_pan_y = 0;
+   wd->reorder_old_pan_y = 0;
    wd->minw = 0;
    wd->minh = 0;
    if (wd->pan_smart)