elementary - backport 82968
authorChunEon Park <hermet@hermet.pe.kr>
Mon, 21 Jan 2013 04:51:59 +0000 (04:51 +0000)
committerChunEon Park <hermet@hermet.pe.kr>
Mon, 21 Jan 2013 04:51:59 +0000 (04:51 +0000)
SVN revision: 83032

ChangeLog
NEWS
src/bin/test_ctxpopup.c
src/lib/elc_ctxpopup.c

index 2abf667fca01560cd7503beaf17563e7a4721fa4..6694d9aca9d5286f9c1b7e29c32ab4fea812026f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
 2013-01-19  WooHyun Jung
 
         * When string in entry is changed, access to sd should be forbidden after smart_callback_call is called.
+
+2013-01-18  Thiep Ha (thiep.ha@samsung.com)
+
+        * Fix memory leak of the ctxpopup and callback function to be a ctxpoup obj is delivered to.
+
diff --git a/NEWS b/NEWS
index e863431a65c9950d2c50b131605640f1f423157e..b6f15725a12270a1503a3ce71ad5f79edcddd057 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,8 @@ Fixes:
 
    * when parent of ctxpopup is resized, ctxpopup calls dismissed signal.
    * When string in entry is changed, access to sd should be forbidden after smart_callback_call is called.
+   * Fix memory leak of the ctxpopup and callback function to be ctxpopup obj is delivered to.
+
 
 Elementary 1.7.5
 
index d12d6213da4b3b75362285abb731296172ef34cb..dfe7714213817a6aea338e65176a73cf81096249 100644 (file)
@@ -283,6 +283,48 @@ _list_item_cb6(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSE
    evas_object_smart_callback_add(btn, "clicked", _btn_clicked, ctxpopup);
 }
 
+static void
+_ctxpopup_item_disable_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
+{
+   printf("ctxpopup item selected: %s\n",
+          elm_object_item_text_get(event_info));
+
+   Elm_Object_Item *it = (Elm_Object_Item *)event_info;
+   elm_object_item_disabled_set(it, EINA_TRUE);
+}
+
+static void
+_ctxpopup_item_delete_cb(void *data __UNUSED__, Evas_Object *obj, void *event_info)
+{
+   printf("ctxpopup item selected: %s\n",
+          elm_object_item_text_get(event_info));
+
+   evas_object_del(obj);
+}
+
+static void
+_list_item_cb7(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
+{
+   Evas_Object *ctxpopup;
+   Evas_Coord x,y;
+
+   ctxpopup = elm_ctxpopup_add(obj);
+   evas_object_smart_callback_add(ctxpopup,
+                                  "dismissed",
+                                  _dismissed,
+                                  NULL);
+
+   elm_ctxpopup_item_append(ctxpopup, "Disable this item", NULL, _ctxpopup_item_disable_cb, ctxpopup);
+   elm_ctxpopup_item_append(ctxpopup, "Delete this ctxpopup", NULL, _ctxpopup_item_delete_cb, ctxpopup);
+   elm_ctxpopup_item_append(ctxpopup, "Another item", NULL, _ctxpopup_item_cb, NULL);
+
+   evas_pointer_canvas_xy_get(evas_object_evas_get(obj), &x, &y);
+   evas_object_size_hint_max_set(ctxpopup, 240, 240);
+   evas_object_move(ctxpopup, x, y);
+   evas_object_show(ctxpopup);
+   _print_current_dir(ctxpopup);
+}
+
 static void _list_clicked(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
 {
    elm_list_item_selected_set(event_info, EINA_FALSE);
@@ -315,6 +357,8 @@ test_ctxpopup(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_in
                         _list_item_cb5, NULL);
    elm_list_item_append(list, "Ctxpopup with restacking", NULL, NULL,
                         _list_item_cb6, NULL);
+   elm_list_item_append(list, "Ctxpopup with callback function", NULL, NULL,
+                        _list_item_cb7, NULL);
    evas_object_show(list);
    elm_list_go(list);
 
index 278401d64047e106149ae1bce94ed887bc15501d..ce4eac952142a28c8e84735ad730852a40c6b7c7 100644 (file)
@@ -8,6 +8,13 @@ struct _Elm_Ctxpopup_Item
 {
    ELM_WIDGET_ITEM;
    Elm_Object_Item *list_item;
+
+   struct
+     {
+        Evas_Smart_Cb org_func_cb;
+        const void    *org_data;
+        Evas_Object   *cobj;
+     } wcb;
 };
 
 struct _Widget_Data
@@ -17,6 +24,7 @@ struct _Widget_Data
    Evas_Object *content;
    Evas_Object *list;
    Evas_Object *box;
+   Eina_List   *items;
    Evas_Object *arrow;
    Evas_Object *bg;
    Elm_Ctxpopup_Direction dir;
@@ -127,6 +135,7 @@ static void _disable_hook(Evas_Object *obj);
 static void _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source);
 static void _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data);
 static void _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data);
+static void _item_wrap_cb(void *data, Evas_Object *obj, void *event_info);
 
 static const char SIG_DISMISSED[] = "dismissed";
 
@@ -751,6 +760,7 @@ static void
 _del_hook(Evas_Object *obj)
 {
    Widget_Data *wd;
+   Elm_Ctxpopup_Item *it;
 
    wd = elm_widget_data_get(obj);
    if (!wd) return;
@@ -758,6 +768,9 @@ _del_hook(Evas_Object *obj)
    elm_ctxpopup_clear(obj);
    evas_object_del(wd->arrow);
    evas_object_del(wd->base);
+
+   EINA_LIST_FREE (wd->items, it)
+     elm_widget_item_free(it);
    free(wd);
 }
 
@@ -1127,11 +1140,13 @@ _item_del_pre_hook(Elm_Object_Item *it)
    if (eina_list_count(elm_list_items_get(list)) < 2)
      {
         elm_object_item_del(ctxpopup_it->list_item);
+        wd->items = eina_list_remove(wd->items, it);
         evas_object_hide(WIDGET(ctxpopup_it));
         return EINA_TRUE;
      }
 
    elm_object_item_del(ctxpopup_it->list_item);
+   wd->items = eina_list_remove(wd->items, it);
    if (wd->list_visible)
      _sizing_eval(WIDGET(ctxpopup_it));
 
@@ -1172,6 +1187,13 @@ _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *so
    edje_object_signal_callback_del_full(wd->base, emission, source, func_cb, data);
 }
 
+static void
+_item_wrap_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
+{
+   Elm_Ctxpopup_Item *item = data;
+   item->wcb.org_func_cb((void *)item->wcb.org_data, item->wcb.cobj, item);
+}
+
 EAPI Evas_Object *
 elm_ctxpopup_add(Evas_Object *parent)
 {
@@ -1386,7 +1408,11 @@ elm_ctxpopup_item_append(Evas_Object *obj, const char *label,
         _content_set_hook(obj, "default", wd->list);
      }
 
-   item->list_item = elm_list_item_append(wd->list, label, icon, NULL, func, data);
+   item->wcb.org_func_cb = func;
+   item->wcb.org_data = data;
+   item->wcb.cobj = obj;
+   item->list_item = elm_list_item_append(wd->list, label, icon, NULL, _item_wrap_cb, item);
+   wd->items = eina_list_append(wd->items, item);
 
    wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;