summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordavemds <dave@gurumeditation.it>2014-08-09 17:53:46 +0200
committerdavemds <dave@gurumeditation.it>2014-08-09 17:53:46 +0200
commit4059e2b5c3a93033e3926b2e4939206cfa504422 (patch)
tree8d86915f455e9a950435ae03ae20c68219ba6ffb
parent708dd2ea88cc2f402f0399cd265dbc5ef443decb (diff)
Genlist: do not segv if the user clear the list on item double-click
@fix moved the user callbacks call at the end of the function, so the user is able to modify the list without making the code below the call to fail miserably. Also improved the Genlist Del test to also include this case.
-rw-r--r--src/bin/test_genlist.c32
-rw-r--r--src/lib/elm_genlist.c23
2 files changed, 39 insertions, 16 deletions
diff --git a/src/bin/test_genlist.c b/src/bin/test_genlist.c
index 0d80d1c58..c6d65c79a 100644
--- a/src/bin/test_genlist.c
+++ b/src/bin/test_genlist.c
@@ -3750,6 +3750,16 @@ _gl_del_unrealized_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
3750 printf("unrealized item # %d\n", num); 3750 printf("unrealized item # %d\n", num);
3751} 3751}
3752 3752
3753static void
3754_gl_del_doubleclick_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
3755 void *event_info)
3756{
3757 int num = (int)(uintptr_t)elm_object_item_data_get(event_info);
3758 int num_category = num % 4;
3759
3760 if (num_category == 3)
3761 elm_genlist_clear(obj);
3762}
3753static Evas_Object * 3763static Evas_Object *
3754_gl_del_genlist_add(Evas_Object *bx) 3764_gl_del_genlist_add(Evas_Object *bx)
3755{ 3765{
@@ -3762,6 +3772,8 @@ _gl_del_genlist_add(Evas_Object *bx)
3762 evas_object_show(gl); 3772 evas_object_show(gl);
3763 evas_object_smart_callback_add(gl, "unrealized", 3773 evas_object_smart_callback_add(gl, "unrealized",
3764 _gl_del_unrealized_cb, NULL); 3774 _gl_del_unrealized_cb, NULL);
3775 evas_object_smart_callback_add(gl, "clicked,double",
3776 _gl_del_doubleclick_cb, NULL);
3765 3777
3766 return gl; 3778 return gl;
3767} 3779}
@@ -3786,15 +3798,20 @@ char *_gl_del_text_get(void *data, Evas_Object *obj EINA_UNUSED,
3786{ 3798{
3787 char buf[256] = { 0 }; 3799 char buf[256] = { 0 };
3788 int num = (int)(uintptr_t)data; 3800 int num = (int)(uintptr_t)data;
3789 int num_category = num % 3; 3801 int num_category = num % 4;
3790 3802
3791 if (num_category == 0) 3803 if (num_category == 0)
3792 snprintf(buf, sizeof(buf), "Item # %i - Item Del", num); 3804 snprintf(buf, sizeof(buf),
3805 "Item #%.02i - 1. Item Del", num);
3793 else if (num_category == 1) 3806 else if (num_category == 1)
3794 snprintf(buf, sizeof(buf), "Item # %i - Genlist Clear and Item Append", 3807 snprintf(buf, sizeof(buf),
3795 num); 3808 "Item #%.02i - 2. Genlist Clear and Item Append", num);
3796 else if (num_category == 2) 3809 else if (num_category == 2)
3797 snprintf(buf, sizeof(buf), "Item # %i - Genlist Del", num); 3810 snprintf(buf, sizeof(buf),
3811 "Item #%.02i - 3. Genlist Del", num);
3812 else if (num_category == 3)
3813 snprintf(buf, sizeof(buf),
3814 "Item #%.02i - 4. Genlist Clear on double-click", num);
3798 3815
3799 return strdup(buf); 3816 return strdup(buf);
3800} 3817}
@@ -3803,7 +3820,7 @@ static void
3803_gl_del_sel(void *data, Evas_Object *obj, void *event_info) 3820_gl_del_sel(void *data, Evas_Object *obj, void *event_info)
3804{ 3821{
3805 int num = (int)(uintptr_t)data; 3822 int num = (int)(uintptr_t)data;
3806 int num_category = num % 3; 3823 int num_category = num % 4;
3807 Elm_Object_Item *it = event_info; 3824 Elm_Object_Item *it = event_info;
3808 Elm_Genlist_Item_Class *itc = 3825 Elm_Genlist_Item_Class *itc =
3809 (Elm_Genlist_Item_Class *)elm_genlist_item_item_class_get(it); 3826 (Elm_Genlist_Item_Class *)elm_genlist_item_item_class_get(it);
@@ -3856,7 +3873,8 @@ test_genlist_del(void *data EINA_UNUSED,
3856 " on item selection.<br/>" 3873 " on item selection.<br/>"
3857 " 1. genlist item deletion<br/>" 3874 " 1. genlist item deletion<br/>"
3858 " 2. genlist clear and item append<br/>" 3875 " 2. genlist clear and item append<br/>"
3859 " 3. genlist del</align>"); 3876 " 3. genlist del<br/>"
3877 " 4. genlist clear on double-click</align>");
3860 elm_object_content_set(fr, lb); 3878 elm_object_content_set(fr, lb);
3861 evas_object_show(lb); 3879 evas_object_show(lb);
3862 3880
diff --git a/src/lib/elm_genlist.c b/src/lib/elm_genlist.c
index 548cd4651..0631279d6 100644
--- a/src/lib/elm_genlist.c
+++ b/src/lib/elm_genlist.c
@@ -3868,15 +3868,7 @@ _item_mouse_down_cb(void *data,
3868 else sd->on_hold = EINA_FALSE; 3868 else sd->on_hold = EINA_FALSE;
3869 if (sd->on_hold) return; 3869 if (sd->on_hold) return;
3870 sd->wasselected = it->selected; 3870 sd->wasselected = it->selected;
3871 it->highlight_cb(it); 3871
3872 if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
3873 if ((!elm_widget_item_disabled_get(it)) &&
3874 (it->select_mode != ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY))
3875 {
3876 evas_object_smart_callback_call(WIDGET(it), SIG_CLICKED_DOUBLE, it);
3877 evas_object_smart_callback_call(WIDGET(it), SIG_ACTIVATED, it);
3878 }
3879 evas_object_smart_callback_call(WIDGET(it), SIG_PRESSED, it);
3880 ecore_timer_del(it->item->swipe_timer); 3872 ecore_timer_del(it->item->swipe_timer);
3881 it->item->swipe_timer = ecore_timer_add(SWIPE_TIME, _swipe_cancel, it); 3873 it->item->swipe_timer = ecore_timer_add(SWIPE_TIME, _swipe_cancel, it);
3882 ELM_SAFE_FREE(it->long_timer, ecore_timer_del); 3874 ELM_SAFE_FREE(it->long_timer, ecore_timer_del);
@@ -3887,6 +3879,19 @@ _item_mouse_down_cb(void *data,
3887 it->long_timer = NULL; 3879 it->long_timer = NULL;
3888 sd->swipe = EINA_FALSE; 3880 sd->swipe = EINA_FALSE;
3889 sd->movements = 0; 3881 sd->movements = 0;
3882
3883 // and finally call the user callbacks.
3884 // NOTE: keep this code at the bottom, as the user can change the
3885 // list at this point (clear, delete, etc...)
3886 it->highlight_cb(it);
3887 if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
3888 if ((!elm_widget_item_disabled_get(it)) &&
3889 (it->select_mode != ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY))
3890 {
3891 evas_object_smart_callback_call(WIDGET(it), SIG_CLICKED_DOUBLE, it);
3892 evas_object_smart_callback_call(WIDGET(it), SIG_ACTIVATED, it);
3893 }
3894 evas_object_smart_callback_call(WIDGET(it), SIG_PRESSED, it);
3890} 3895}
3891 3896
3892static Item_Block * 3897static Item_Block *