[elm_genlist.c test_genlist.c] Applied SVN Revision 54639.
authorDaniel Juyung Seo <juyung.seo@samsung.com>
Thu, 18 Nov 2010 00:38:21 +0000 (09:38 +0900)
committerDaniel Juyung Seo <juyung.seo@samsung.com>
Thu, 18 Nov 2010 00:38:21 +0000 (09:38 +0900)
Changeset 54639
Timestamp: 11/17/10 09:15:28 (7 hours ago)
Author: bdilly
Message: Add elm_genlist_item_item_class_update

1. elm_genlist_item_item_class_update() API
It is required to change an item's item class on run-time.
Applications want to change a certain item's style and callbacks
dynamically.
This looks ok because changing one item's style does not affect performance,
And this API uses elm_genlist_item_update internally.
API name follows elementary naming conventions.
I've also added test code to elementary_test, Genlist 7.

2. constant to macro.
I replaced 2 constants for max_item_per_block and longpress_timeout to
macros.
This could be used in other places of the code.

3. duplicated assignment.
In elm_genlist_item_append, it->before = 0 is written in if and else.
I put this statement out of if().

4. fix doxygen typo
I fixed elm_genlist_compress_mode_set doxygen.

By: Daniel Juyung Seo <juyung.seo@...>

src/bin/test.c
src/bin/test_genlist.c
src/lib/Elementary.h.in
src/lib/elm_genlist.c

index 7a8ad4e..d9ba5c4 100644 (file)
@@ -42,6 +42,7 @@ void test_genlist3(void *data, Evas_Object *obj, void *event_info);
 void test_genlist4(void *data, Evas_Object *obj, void *event_info);
 void test_genlist5(void *data, Evas_Object *obj, void *event_info);
 void test_genlist6(void *data, Evas_Object *obj, void *event_info);
+void test_genlist7(void *data, Evas_Object *obj, void *event_info);
 void test_table(void *data, Evas_Object *obj, void *event_info);
 void test_gengrid(void *data, Evas_Object *obj, void *event_info);
 void test_pager(void *data, Evas_Object *obj, void *event_info);
@@ -239,6 +240,7 @@ my_win_main(void)
    ADD_TEST("Genlist 3", test_genlist3);
    ADD_TEST("Genlist 4", test_genlist4);
    ADD_TEST("Genlist 5", test_genlist5);
+   ADD_TEST("Genlist 7", test_genlist7);
    ADD_TEST("Genlist Tree", test_genlist6);
    ADD_TEST("GenGrid", test_gengrid);
    ADD_TEST("Checks", test_check);
index 80e0f74..30d7063 100644 (file)
@@ -1207,4 +1207,128 @@ test_genlist6(void *data, Evas_Object *obj, void *event_info)
    evas_object_resize(win, 320, 320);
    evas_object_show(win);
 }
+
+/*************/
+
+struct genlist7_data
+{
+  Evas_Object *win, *pager;
+};
+
+static Elm_Genlist_Item_Class itc7;
+static void
+gl_sel7(void *data, Evas_Object *obj, void *event_info)
+{
+   if (!event_info) return;
+   elm_genlist_item_item_class_update(event_info, &itc7);
+   printf("sel item data [%p] on genlist obj [%p], item pointer [%p], new item style [%s] \n", data, obj, event_info, itc7.item_style);
+}
+
+static void
+test_genlist7_back_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
+{
+    struct genlist7_data *info = data;
+    if (!info) return;
+
+    elm_pager_content_pop(info->pager);
+}
+
+static void
+test_genlist7_swipe(void *data, Evas_Object *obj __UNUSED__, void *event_info)
+{
+   struct genlist7_data *info = data;
+   Evas_Object *box, *entry, *button;
+   char item_data[] = "Just a simple test";
+
+   if ((!event_info) || (!data)) return;
+
+   box = elm_box_add(info->win);
+   elm_box_homogenous_set(box, 0);
+   evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+   evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
+   evas_object_show(box);
+
+   entry = elm_scrolled_entry_add(info->win);
+   elm_scrolled_entry_editable_set(entry, EINA_FALSE);
+   elm_scrolled_entry_entry_set(entry, item_data);
+   evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+   evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
+   evas_object_show(entry);
+
+   button = elm_button_add(info->win);
+   elm_button_label_set(button, "back");
+   evas_object_size_hint_weight_set(button, EVAS_HINT_EXPAND, 0);
+   evas_object_size_hint_align_set(button, EVAS_HINT_FILL, 0);
+   evas_object_smart_callback_add(button, "clicked", test_genlist7_back_cb,
+                                  info);
+   evas_object_show(button);
+
+   elm_box_pack_start(box, entry);
+   elm_box_pack_end(box, button);
+
+   elm_pager_content_push(info->pager, box);
+}
+
+void
+test_genlist7(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
+{
+   Evas_Object *win, *bg, *gl, *pager;
+   static struct genlist7_data info;
+   static Testitem tit[3];
+
+   win = elm_win_add(NULL, "genlist-7", ELM_WIN_BASIC);
+   elm_win_title_set(win, "Genlist 7");
+   elm_win_autodel_set(win, 1);
+   info.win = win;
+
+   bg = elm_bg_add(win);
+   elm_win_resize_object_add(win, bg);
+   evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+   evas_object_show(bg);
+
+   pager = elm_pager_add(win);
+   elm_win_resize_object_add(win, pager);
+   evas_object_size_hint_weight_set(pager, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+   evas_object_size_hint_align_set(pager, EVAS_HINT_FILL, EVAS_HINT_FILL);
+   evas_object_show(pager);
+   info.pager = pager;
+
+   gl = elm_genlist_add(win);
+   evas_object_size_hint_align_set(gl, EVAS_HINT_FILL, EVAS_HINT_FILL);
+   evas_object_size_hint_weight_set(gl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+   evas_object_smart_callback_add(gl, "swipe", test_genlist7_swipe, &info);
+   evas_object_show(gl);
+   elm_pager_content_push(pager, gl);
+
+   itc2.item_style     = "default";
+   itc2.func.label_get = gl2_label_get;
+   itc2.func.icon_get  = gl2_icon_get;
+   itc2.func.state_get = gl2_state_get;
+   itc2.func.del       = gl2_del;
+
+   itc7.item_style     = "double_label";
+   itc7.func.label_get = gl5_label_get;
+   itc7.func.icon_get  = gl5_icon_get;
+   itc7.func.state_get = gl5_state_get;
+   itc7.func.del       = gl5_del;
+
+   tit[0].mode = 0;
+   tit[0].item = elm_genlist_item_append(gl, &itc2,
+                                        &(tit[0])/* item data */, NULL/* parent */,
+                                         ELM_GENLIST_ITEM_NONE, gl_sel7/* func */,
+                                        NULL/* func data */);
+   tit[1].mode = 1;
+   tit[1].item = elm_genlist_item_append(gl, &itc2,
+                                        &(tit[1])/* item data */, NULL/* parent */,
+                                         ELM_GENLIST_ITEM_NONE, gl_sel7/* func */,
+                                        NULL/* func data */);
+   tit[2].mode = 2;
+   tit[2].item = elm_genlist_item_append(gl, &itc2,
+                                        &(tit[2])/* item data */, NULL/* parent */,
+                                         ELM_GENLIST_ITEM_NONE, gl_sel7/* func */,
+                                        NULL/* func data */);
+
+   evas_object_resize(win, 320, 320);
+   evas_object_show(win);
+}
 #endif
index e50d45d..687d453 100644 (file)
@@ -1261,13 +1261,6 @@ extern "C" {
    EAPI int               elm_genlist_block_count_get(const Evas_Object *obj);
    EAPI void              elm_genlist_longpress_timeout_set(Evas_Object *obj, double timeout);
    EAPI double            elm_genlist_longpress_timeout_get(const Evas_Object *obj);
-   EAPI void              elm_genlist_effect_set(const Evas_Object *obj, Eina_Bool emode);
-   EAPI void              elm_genlist_pinch_zoom_set(Evas_Object *obj, Eina_Bool emode);
-   EAPI void              elm_genlist_pinch_zoom_mode_set(Evas_Object *obj, Eina_Bool emode);
-   EAPI Eina_Bool         elm_genlist_pinch_zoom_mode_get(const Evas_Object *obj);
-   EINA_DEPRECATED EAPI void              elm_genlist_queue_exception_set(const Evas_Object *obj, Eina_Bool emode);
-
-
    /* operations to add items */
    EAPI Elm_Genlist_Item *elm_genlist_item_append(Evas_Object *obj, const Elm_Genlist_Item_Class *itc, const void *data, Elm_Genlist_Item *parent, Elm_Genlist_Item_Flags flags, Evas_Smart_Cb func, const void *func_data);
    EAPI Elm_Genlist_Item *elm_genlist_item_prepend(Evas_Object *obj, const Elm_Genlist_Item_Class *itc, const void *data, Elm_Genlist_Item *parent, Elm_Genlist_Item_Flags flags, Evas_Smart_Cb func, const void *func_data);
@@ -1286,7 +1279,6 @@ extern "C" {
     * double_label
     * icon_top_text_bottom
     */
-
    /* Genlist Item operation */
    EAPI Elm_Genlist_Item *elm_genlist_item_next_get(const Elm_Genlist_Item *item);
    EAPI Elm_Genlist_Item *elm_genlist_item_prev_get(const Elm_Genlist_Item *item);
@@ -1297,6 +1289,7 @@ extern "C" {
    EAPI Eina_Bool         elm_genlist_item_selected_get(const Elm_Genlist_Item *item);
    EAPI void              elm_genlist_item_expanded_set(Elm_Genlist_Item *item, Eina_Bool expanded);
    EAPI Eina_Bool         elm_genlist_item_expanded_get(const Elm_Genlist_Item *item);
+   EAPI int               elm_genlist_item_expanded_depth_get(const Elm_Genlist_Item *it);
    EAPI void              elm_genlist_item_disabled_set(Elm_Genlist_Item *item, Eina_Bool disabled);
    EAPI Eina_Bool         elm_genlist_item_disabled_get(const Elm_Genlist_Item *item);
    EAPI void              elm_genlist_item_display_only_set(Elm_Genlist_Item *it, Eina_Bool display_only);
@@ -1312,10 +1305,10 @@ extern "C" {
    EAPI void              elm_genlist_item_data_set(Elm_Genlist_Item *it, const void *data);
    EAPI const Evas_Object *elm_genlist_item_object_get(const Elm_Genlist_Item *it);
    EAPI void              elm_genlist_item_update(Elm_Genlist_Item *item);
+   EAPI void              elm_genlist_item_item_class_update(Elm_Genlist_Item *it, const Elm_Genlist_Item_Class *itc);
    EAPI void              elm_genlist_scroller_policy_set(Evas_Object *obj, Elm_Scroller_Policy policy_h, Elm_Scroller_Policy policy_v);
    EINA_DEPRECATED EAPI void elm_genlist_set_edit_mode(Evas_Object *obj, int emode, Elm_Genlist_Edit_Class *ec);
    EAPI void              elm_genlist_edit_mode_set(Evas_Object *obj, int emode, Elm_Genlist_Edit_Class *ec);
-   EAPI int               elm_genlist_item_expanded_depth_get(const Elm_Genlist_Item *it);
    EAPI void              elm_genlist_edit_selected_items_del(Evas_Object *obj);
    EINA_DEPRECATED EAPI void elm_genlist_selected_items_del(Evas_Object *obj);
    EAPI Eina_List *       elm_genlist_edit_selected_items_get(const Evas_Object *obj);
@@ -1325,6 +1318,11 @@ extern "C" {
    EAPI void              elm_genlist_groupitem_del( Elm_Genlist_GroupItem *git);
    EAPI Elm_Genlist_Item *elm_genlist_item_append_with_group(Evas_Object *obj, const Elm_Genlist_Item_Class *itc, const void *data, Elm_Genlist_Item *parent, Elm_Genlist_Item_Flags flags, Elm_Genlist_GroupItem *git, void (*func) (void *data, Evas_Object *obj, void *event_info), const void *func_data);   
    EAPI void              elm_genlist_item_move_after(Elm_Genlist_Item *it, Elm_Genlist_Item *after );
+   EAPI void              elm_genlist_effect_set(const Evas_Object *obj, Eina_Bool emode);
+   EAPI void              elm_genlist_pinch_zoom_set(Evas_Object *obj, Eina_Bool emode);
+   EAPI void              elm_genlist_pinch_zoom_mode_set(Evas_Object *obj, Eina_Bool emode);
+   EAPI Eina_Bool         elm_genlist_pinch_zoom_mode_get(const Evas_Object *obj);
+   EINA_DEPRECATED EAPI void              elm_genlist_queue_exception_set(const Evas_Object *obj, Eina_Bool emode);
 
    EAPI Evas_Object *elm_check_add(Evas_Object *parent);
    EAPI void         elm_check_label_set(Evas_Object *obj, const char *label);
index a5091f9..a7e21e6 100644 (file)
@@ -3,6 +3,8 @@
 #include "els_scroller.h"
 
 #define SWIPE_MOVES 12
+#define MAX_ITEMS_PER_BLOCK 32
+#define LONGPRESS_TIMEOUT 1.0
 
 /**
  * @defgroup Genlist Genlist
@@ -2547,8 +2549,9 @@ elm_genlist_add(Evas_Object *parent)
 
    wd->obj = obj;
    wd->mode = ELM_LIST_SCROLL;
+   wd->max_items_per_block = MAX_ITEMS_PER_BLOCK;
    wd->max_items_per_block = 32;
-   wd->longpress_timeout = 1.0;
+   wd->longpress_timeout = LONGPRESS_TIMEOUT;
        wd->max_git_num = 0;
 
    evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
@@ -2862,7 +2865,6 @@ elm_genlist_item_append(Evas_Object *obj, const Elm_Genlist_Item_Class *itc,
      {
         wd->items = eina_inlist_append(wd->items, EINA_INLIST_GET(it));
         it->rel = NULL;
-        it->before = 0;
      }
    else
      {
@@ -2876,8 +2878,8 @@ elm_genlist_item_append(Evas_Object *obj, const Elm_Genlist_Item_Class *itc,
                                        EINA_INLIST_GET(it2));
         it->rel = it2;
         it->rel->relcount++;
-        it->before = 0;
      }
+   it->before = 0;
    _item_queue(wd, it);
    return it;
 }
@@ -3997,6 +3999,25 @@ elm_genlist_item_update(Elm_Genlist_Item *it)
 }
 
 /**
+ * Update the item class of an item
+ *
+ * @param it The item
+ * @parem itc The item class for the item
+ *
+ * @ingroup Genlist
+ */
+EAPI void
+elm_genlist_item_item_class_update(Elm_Genlist_Item *it, const Elm_Genlist_Item_Class *itc)
+{
+   if (!it) return;
+   if (!it->block) return;
+   if (!itc) return;
+   if (it->delete_me) return;
+   it->itc = itc;
+   elm_genlist_item_update(it);
+}
+
+/**
  * This sets the horizontal stretching mode
  *
  * This sets the mode used for sizing items horizontally. Valid modes are
@@ -4124,8 +4145,8 @@ elm_genlist_no_select_mode_get(const Evas_Object *obj)
  * Set compress mode
  *
  * This will enable the compress mode where items are "compressed" horizontally
- * to fit the genlist scrollable viewport width. this is special for gnelist.
- * do not rely on elm_genlist_horizontal_mode_set() being set to
+ * to fit the genlist scrollable viewport width. This is special for genlist.
+ * Do not rely on elm_genlist_horizontal_mode_set() being set to
  * ELM_LIST_COMPRESS to work as genlist needs to handle it specially.
  *
  * @param obj The genlist object