Fix seg fault bug 93/38093/2
authorJuWan Kim <juwan.kim@samsung.com>
Sat, 11 Apr 2015 02:46:00 +0000 (11:46 +0900)
committerJuWan Kim <juwan.kim@samsung.com>
Sat, 11 Apr 2015 02:48:51 +0000 (11:48 +0900)
   * When refactoring, passed wrong parameter

Change-Id: I0e3f200df6e2d90b2e16d5bee4457de7cb89e656
Signed-off-by: JuWan Kim <juwan.kim@samsung.com>
include/view_sublist.h
src/utils.cpp
src/view_sublist.cpp

index 1f7ffcf..ba58368 100644 (file)
@@ -36,10 +36,11 @@ private:
        static void sm_CbCtxpopupDismissed(void *data, Evas_Object *obj, void *ev);
        void m_OnCtxpopupDismissed(Evas_Object *obj, void *ev);
 
+       bool m_DrawCtxpopupLayout(void);
        bool m_DrawSublist(void);
        void m_ExitView(void);
        void m_SetSelectedValue(Evas_Object *obj);
-       int m_DrawListItems(Eina_List *list);
+       bool m_DrawListItems(Eina_List *list);
 
 public:
        CSublistView(const char *pViewId) : 
index 39f52c3..01f90e6 100644 (file)
@@ -140,10 +140,8 @@ Evas_Object *utils_add_btn(Evas_Object *base,
        if (!btn)
                return NULL;
 
-       evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND,
-                       EVAS_HINT_EXPAND);
-       evas_object_size_hint_align_set(btn, EVAS_HINT_FILL,
-                       EVAS_HINT_FILL);
+       evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+       evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
 
        if (style)
                elm_object_style_set(btn, style);
@@ -152,10 +150,8 @@ Evas_Object *utils_add_btn(Evas_Object *base,
                elm_object_text_set(btn, utils_get_translation_str(text));
 
        if (event == EINA_TRUE) {
-               evas_object_event_callback_add(btn, EVAS_CALLBACK_MOUSE_IN,
-                               _btn_mouse_in_cb, NULL);
-               evas_object_event_callback_add(btn, EVAS_CALLBACK_MOUSE_OUT,
-                               _btn_mouse_out_cb, NULL);
+               evas_object_event_callback_add(btn, EVAS_CALLBACK_MOUSE_IN, _btn_mouse_in_cb, NULL);
+               evas_object_event_callback_add(btn, EVAS_CALLBACK_MOUSE_OUT, _btn_mouse_out_cb, NULL);
        }
 
        evas_object_show(btn);
@@ -182,17 +178,16 @@ Evas_Object *utils_add_scroller(Evas_Object *base)
        if (!scroller)
                return NULL;
 
-       evas_object_size_hint_weight_set(scroller,
-                       EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
-       evas_object_size_hint_align_set(scroller,
-                       EVAS_HINT_FILL, EVAS_HINT_FILL);
+       evas_object_size_hint_weight_set(scroller, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+       evas_object_size_hint_align_set(scroller, EVAS_HINT_FILL, EVAS_HINT_FILL);
 
+#if 0
        elm_scroller_bounce_set(scroller, EINA_FALSE, EINA_FALSE);
-       elm_scroller_policy_set(scroller, ELM_SCROLLER_POLICY_OFF,
-                       ELM_SCROLLER_POLICY_OFF);
+       elm_scroller_policy_set(scroller, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF);
        elm_object_focus_allow_set(scroller, EINA_FALSE);
 
        evas_object_show(scroller);
+#endif
 
        return scroller;
 }
@@ -216,10 +211,8 @@ Evas_Object *utils_add_box(Evas_Object *base)
        if (!box)
                return NULL;
 
-       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_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+       evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
        elm_object_focus_allow_set(box, EINA_FALSE);
 
        evas_object_show(box);
index fbe642f..1f5b6f2 100644 (file)
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include "AppCommon.h"
 #include "dbg.h"
 #include "def.h"
 #include "stdbool.h"
@@ -71,6 +72,8 @@ struct SSublistView {
 */
 void CSublistView::m_ExitView(void)
 {
+       _DBG();
+
        Hide();
        
        m->mgr->ViewPop();
@@ -237,6 +240,7 @@ static void _scroll_event_cb(void *data, Evas_Object *obj, void *event)
 */
 void CSublistView::sm_CbCtxpopupDismissed(void *data, Evas_Object *obj, void *ev)
 {
+       _DBG();
        CSublistView *root = (CSublistView*)data;
        if (root)
                root->m_OnCtxpopupDismissed(obj, ev);
@@ -245,6 +249,7 @@ void CSublistView::sm_CbCtxpopupDismissed(void *data, Evas_Object *obj, void *ev
 
 void CSublistView::m_OnCtxpopupDismissed(Evas_Object *obj, void *ev)
 {
+       _DBG();
        m_ExitView();
 }
 
@@ -255,61 +260,51 @@ void CSublistView::m_OnCtxpopupDismissed(Evas_Object *obj, void *ev)
 *  @param data [in] The _sublist_data data pointer.
 *  @return 0 if success, -1 if fail.
 */
-static int _draw_ctxpopup_layout(SSublistView *data)
+bool CSublistView::m_DrawCtxpopupLayout()
 {
-       Evas_Object *box, *ctxpopup, *scroller;
-
-       if (!data || !data->ctxpopup) {
+       _DBG();
+       if (!m->ctxpopup) {
                _ERR("Invalid argument");
-               return -1;
+               return false;
        }
 
-       ctxpopup = data->ctxpopup;
-       scroller = NULL;
-
-       if (data->sub_items_count > MAX_ITEMS) {
-               scroller = utils_add_scroller(ctxpopup);
-               if (!scroller) {
-                       _ERR("elm_scroller_add failed\n");
-                       return -1;
+       if (m->sub_items_count > MAX_ITEMS) {
+               m->scroller = utils_add_scroller(m->ctxpopup);
+               if (!m->scroller) {
+                       _ERR("elm_scroller_add failed");
+                       return false;
                }
 
-               elm_object_style_set(scroller, SUBLIST_SCROLLER_STYLE);
-               elm_object_content_set(ctxpopup, scroller);
+               //elm_object_style_set(m->scroller, SUBLIST_SCROLLER_STYLE);
+               elm_object_content_set(m->ctxpopup, m->scroller);
 
-               box = utils_add_box(ctxpopup);
-               if (!box) {
-                       _ERR("elm_box_add failed\n");
-                       evas_object_del(scroller);
-                       return -1;
+               m->popup_box = utils_add_box(m->ctxpopup);
+               if (!m->popup_box) {
+                       _ERR("elm_box_add failed");
+                       evas_object_del(m->scroller);
+                       return false;
                }
 
-               elm_object_content_set(scroller, box);
+               elm_object_content_set(m->scroller, m->popup_box);
 
-               evas_object_smart_callback_add(scroller, SIG_SCROLL_BOTTOM,
-                               _scroller_bottom_cb, data);
-               evas_object_smart_callback_add(scroller, SIG_SCROLL_TOP,
-                               _scroller_top_cb, data);
-               evas_object_smart_callback_add(scroller, SIG_SCROLL,
-                               _scroll_event_cb, data);
+               evas_object_smart_callback_add(m->scroller, SIG_SCROLL_BOTTOM, _scroller_bottom_cb, m);
+               evas_object_smart_callback_add(m->scroller, SIG_SCROLL_TOP, _scroller_top_cb, m);
+               evas_object_smart_callback_add(m->scroller, SIG_SCROLL, _scroll_event_cb, m);
 
-               elm_object_signal_emit(ctxpopup, SUBLIST_SHOW_DOWN_ARROW, "");
+               elm_object_signal_emit(m->ctxpopup, SUBLIST_SHOW_DOWN_ARROW, "");
        } else {
-               box = utils_add_box(ctxpopup);
-               if (!box) {
-                       _ERR("elm_box_add failed\n");
-                       return -1;
+               m->popup_box = utils_add_box(m->ctxpopup);
+               if (!m->popup_box) {
+                       _ERR("elm_box_add failed");
+                       return false;
                }
 
-               elm_object_content_set(ctxpopup, box);
+               elm_object_content_set(m->ctxpopup, m->popup_box);
 
-               elm_object_signal_emit(ctxpopup, SUBLIST_HIDE_BOTH_ARROW, "");
+               elm_object_signal_emit(m->ctxpopup, SUBLIST_HIDE_BOTH_ARROW, "");
        }
 
-       data->popup_box = box;
-       data->scroller = scroller;
-
-       return 0;
+       return true;
 }
 
 /**
@@ -319,8 +314,9 @@ static int _draw_ctxpopup_layout(SSublistView *data)
 *  @param list [in] The eina list data pointer.
 *  @return 0 if success, -1 if fail.
 */
-int CSublistView::m_DrawListItems(Eina_List *list)
+bool CSublistView::m_DrawListItems(Eina_List *list)
 {
+       _DBG();
        struct listitem *ldata;
        void* obj;
        Eina_List *l;
@@ -333,20 +329,20 @@ int CSublistView::m_DrawListItems(Eina_List *list)
 
        if (!list || !m->popup_box) {
                _ERR("Invalid argument");
-               return -1;
+               return false;
        }
 
        sel = _get_selected_value(m);
        if (!sel) {
                _ERR("Get selected value failed");
-               return -1;
+               return false;
        }
 
        btns = eina_array_new(1);
        if (!btns) {
-               _ERR("Allocate array failed\n");
+               _ERR("Allocate array failed");
                provider_release_list_value(sel);
-               return -1;
+               return false;
        }
 
        i = 0;
@@ -357,10 +353,9 @@ int CSublistView::m_DrawListItems(Eina_List *list)
                ldata = (struct listitem *) obj;
                name = listitem_get_display_name(ldata);
 
-               btn = utils_add_btn(m->popup_box, (char *) CTXPOPUPBTN_STYLE,
-                               name, EINA_TRUE);
+               btn = utils_add_btn(m->popup_box, (char *) CTXPOPUPBTN_STYLE, name, EINA_TRUE);
                if (!btn) {
-                       _ERR("Add button failed\n");
+                       _ERR("Add button failed");
                        EINA_ARRAY_ITER_NEXT(btns, j, obj, a)
                        {
                                tmp = (Evas_Object *) obj;
@@ -368,7 +363,7 @@ int CSublistView::m_DrawListItems(Eina_List *list)
                        }
                        eina_array_free(btns);
                        provider_release_list_value(sel);
-                       return -1;
+                       return false;
                }
 
                val = listitem_get_value(ldata);
@@ -402,7 +397,7 @@ int CSublistView::m_DrawListItems(Eina_List *list)
 
        provider_release_list_value(sel);
 
-       return 0;
+       return true;
 }
 
 /**
@@ -413,7 +408,7 @@ int CSublistView::m_DrawListItems(Eina_List *list)
 */
 bool CSublistView::m_DrawSublist(void)
 {
-       struct settingview_data *view;
+       _DBG();
        Eina_List *list;
        double ratio, w;
        int cnt, x, y, height, screen_h;
@@ -424,10 +419,8 @@ bool CSublistView::m_DrawSublist(void)
                return false;
        }
 
-       view = m->sublist_view;
-
        cnt = 0;
-       list = _get_list_data(view, &cnt);
+       list = _get_list_data(m->sublist_view, &cnt);
        if (!list) {
                _ERR("Get item list failed");
                return false;
@@ -435,44 +428,17 @@ bool CSublistView::m_DrawSublist(void)
 
        m->sub_items_count = cnt;
 
-       if (_draw_ctxpopup_layout(m) == -1) {
+       if (!m_DrawCtxpopupLayout()) {
                _ERR("Fail to draw ctxpopup layout");
                return false;
        }
 
-       if (m_DrawListItems(list) == -1) {
+       if (!m_DrawListItems(list)) {
                _ERR("Fail to draw list items");
                return false;
        }
 
-       screen_h = WIN_HEIGHT;
-
-       param = m->geometry_data;
-
-       w = param->width;
-       if (w <= 0) {
-               _ERR("Fail to get clicked button width");
-               return false;
-       }
-
-       ratio = (w - SUBLIST_WIDTH - SUBLIST_OFFSET) / w;
-
-       x = param->x + param->width * ratio;
-       y = param->y;
-
-       if (m->sub_items_count < MAX_ITEMS)
-               height = m->sub_items_count * ITEM_HEIGHT;
-       else
-               height = MAX_ITEMS * ITEM_HEIGHT + ITEM_OFFSET;
-
-       if (y > screen_h)
-       {
-               y = y - height;
-               _DBG("y > screen_h !!!!!! y = %d", y);
-       }
-
-       _DBG("x : %d , y : %d, ELM_SCALE = %f, height = %d", x , y , ELM_SCALE, height);
-       evas_object_move(m->ctxpopup, x * ELM_SCALE, (y * ELM_SCALE) + height);
+       evas_object_move(m->ctxpopup, m->geometry_data->x + m->geometry_data->width , m->geometry_data->y);
 
        utils_set_focus_directions(m->sub_btn_array, m->sub_items_count);
 
@@ -502,59 +468,38 @@ bool CSublistView::Create(struct settingview_data *view, void *prev)
        ASSERT(!m);
        ASSERT(view);
        ASSERT(prev);
-
-       Evas_Object *base, *ctxpopup, *win;
-       CSettingMgr *mgr = CSettingMgr::GetInstance();
-
-       win = mgr->Window();
-       ASSERT(win);
-
-       m = new SSublistView;
-       if (!m) {
-               _ERR("Unable to allocate memory\n");
-               return false;
-       }
-
-       base = elm_layout_add(win);
-       if (!base) {
-               delete m;
-               m = NULL;
-               return false;
-       }
-
-       elm_layout_file_set(base, EDJ_FILE, SUBLIST_VIEW_PAGE);
-
-       ctxpopup = utils_add_ctxpopup(win, (char *) SUBLIST_CTXPOPUP_STYLE1);
-       if (!ctxpopup) {
-               _ERR("Fail to add ctxpopup");
-               evas_object_del(base);
-               delete m;
-               m = NULL;
-               return false;
-       }
-
-       evas_object_smart_callback_add(ctxpopup, SIG_CTXPOPUP_DISMISSED,
-                       sm_CbCtxpopupDismissed, m);
-
-       m->geometry_data = (struct obj_geometry_data *) prev;
-
-       m->mgr = mgr;
-       m->win = win;
-       m->base = base;
-       m->ctxpopup = ctxpopup;
-       m->sublist_view = view;
-
-       if (!m_DrawSublist()) {
-               _ERR("Error in drawing items function\n");
-               evas_object_del(base);
-               evas_object_del(ctxpopup);
-               if (m->sub_btn_array)
-                       eina_array_free(m->sub_btn_array);
-
-               delete m;
-               m = NULL;
-               return false;
-       }
+       _DBG();
+
+       _CREATE_BEGIN {
+               _CHECK(m = new SSublistView)
+               _CHECK(m->mgr = CSettingMgr::GetInstance())
+               _CHECK(m->win = m->mgr->Window())
+               _CHECK(m->base = elm_layout_add(m->win))
+               _COMMAND {
+                       elm_layout_file_set(m->base, EDJ_FILE, SUBLIST_VIEW_PAGE);
+               }
+               _CHECK(m->ctxpopup = utils_add_ctxpopup(m->win, (char *) SUBLIST_CTXPOPUP_STYLE1))
+               _COMMAND {
+                       evas_object_smart_callback_add(m->ctxpopup, SIG_CTXPOPUP_DISMISSED, sm_CbCtxpopupDismissed, this);
+                       m->geometry_data = (struct obj_geometry_data *) prev;
+                       _DBG("m-geometry_data w:%d, h:%d, x:%d, y:%d",
+                                       m->geometry_data->width,
+                                       m->geometry_data->height,
+                                       m->geometry_data->x,
+                                       m->geometry_data->y
+                               );
+
+                       m->sublist_view = view;
+               }
+               _CHECK(m_DrawSublist())
+               _WHEN_SUCCESS { }
+               _CHECK_FAIL{ if (m->sub_btn_array) eina_array_free(m->sub_btn_array); }
+               _CHECK_FAIL{ if(m->ctxpopup) evas_object_del(m->ctxpopup); }
+               _CHECK_FAIL{ if(m->base) evas_object_del(m->base); }
+               _CHECK_FAIL{/* m->win = m->mgr->Window() */}
+               _CHECK_FAIL{/* m->mgr = CSettingMgr::GetInstance() */}
+               _CHECK_FAIL{ delete m; m = NULL; }
+       } _CREATE_END_AND_CATCH{ return false; }
 
        return true;
 }
@@ -568,6 +513,7 @@ bool CSublistView::Create(struct settingview_data *view, void *prev)
 void CSublistView::Show(void)
 {
        ASSERT(m);
+       _DBG();
 
        evas_object_show(m->ctxpopup);
        evas_object_show(m->base);
@@ -582,6 +528,7 @@ void CSublistView::Show(void)
 void CSublistView::Destroy(void)
 {
        ASSERT(m);
+       _DBG();
 
        if (m->sub_btn_array)
                eina_array_free(m->sub_btn_array);
@@ -605,6 +552,7 @@ void CSublistView::Destroy(void)
 void CSublistView::Hide(void)
 {
        ASSERT(m);
+       _DBG();
 
        evas_object_hide(m->base);
        evas_object_hide(m->ctxpopup);
@@ -613,6 +561,7 @@ void CSublistView::Hide(void)
 
 void CSublistView::OnMouseClicked(int id, Evas_Object *obj)
 {
+       _DBG();
        if (id != ID_BTNS)
                return;
 
@@ -627,6 +576,7 @@ void CSublistView::OnMouseClicked(int id, Evas_Object *obj)
 
 void CSublistView::OnFocused(int id, Evas_Object *obj, Elm_Object_Item *item)
 {
+       _DBG();
        if (id != ID_BTNS)
                return;
 
@@ -662,6 +612,7 @@ void CSublistView::OnFocused(int id, Evas_Object *obj, Elm_Object_Item *item)
 
 void CSublistView::OnUnfocused(int id, Evas_Object *obj, Elm_Object_Item *item)
 {
+       _DBG();
        if (id != ID_BTNS)
                return;
 
@@ -697,6 +648,7 @@ void CSublistView::OnUnfocused(int id, Evas_Object *obj, Elm_Object_Item *item)
 
 void CSublistView::OnKeyDown(int id, Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ev)
 {
+       _DBG();
        if (id != ID_BTNS)
                return;