Create elm_list_item_sorted_insert
authorLuis Felipe Strano Moraes <lfelipe@profusion.mobi>
Wed, 12 May 2010 15:43:54 +0000 (15:43 +0000)
committerLuis Felipe Strano Moraes <lfelipe@profusion.mobi>
Wed, 12 May 2010 15:43:54 +0000 (15:43 +0000)
Function that include items to an elm list in a sorted way defined by
an Eina_Compare_Cb function.

Author: Bruno Dilly <bdilly@profusion.mobi>

SVN revision: 48777

src/lib/Elementary.h.in
src/lib/elm_list.c

index 6ede697..29a1d0e 100644 (file)
@@ -965,6 +965,7 @@ extern "C" {
    EAPI Elm_List_Item   *elm_list_item_prepend(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Object *end, Evas_Smart_Cb func, const void *data);
    EAPI Elm_List_Item   *elm_list_item_insert_before(Evas_Object *obj, Elm_List_Item *before, const char *label, Evas_Object *icon, Evas_Object *end, Evas_Smart_Cb func, const void *data);
    EAPI Elm_List_Item   *elm_list_item_insert_after(Evas_Object *obj, Elm_List_Item *after, const char *label, Evas_Object *icon, Evas_Object *end, Evas_Smart_Cb func, const void *data);
+   EAPI Elm_List_Item   *elm_list_item_sorted_insert(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Object *end, Evas_Smart_Cb func, const void *data, Eina_Compare_Cb cmp_func);
    EAPI void             elm_list_clear(Evas_Object *obj);
    EAPI void             elm_list_go(Evas_Object *obj);
    EAPI void             elm_list_multi_select_set(Evas_Object *obj, Eina_Bool multi);
index aff0310..b7844b2 100644 (file)
@@ -874,6 +874,46 @@ elm_list_item_insert_after(Evas_Object *obj, Elm_List_Item *after, const char *l
 }
 
 /**
+ * Insert a new item into the sorted list object.
+ *
+ * @param obj The list object
+ * @param label The label of the list item
+ * @param icon The icon object to use for the left side of the item
+ * @param end The icon object to use for the right side of the item
+ * @param func The function to call when the item is clicked
+ * @param data The data to associate with the item for related callbacks
+ * @param cmp_func The function called for the sort.
+ *
+ * @return The created item or NULL upon failure
+ *
+ * @ingroup List
+ */
+EAPI Elm_List_Item *
+elm_list_item_sorted_insert(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Object *end, Evas_Smart_Cb func, const void *data, Eina_Compare_Cb cmp_func)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype) NULL;
+   Widget_Data *wd = elm_widget_data_get(obj);
+   Elm_List_Item *it = _item_new(obj, label, icon, end, func, data);
+   Eina_List *l;
+
+   wd->items = eina_list_sorted_insert(wd->items, cmp_func, it);
+   l = eina_list_data_find_list(wd->items, it);
+   l = eina_list_next(l);
+   if (!l)
+     {
+       it->node = eina_list_last(wd->items);
+       elm_box_pack_end(wd->box, it->base);
+     }
+   else
+     {
+       Elm_List_Item *before = eina_list_data_get(l);
+       it->node = before->node->prev;
+       elm_box_pack_before(wd->box, it->base, before->base);
+     }
+   return it;
+}
+
+/**
  * Clears a list of all items.
  *
  * @param obj The list object