Add util function for creating ctxpopup 07/47307/2
authorHyojung Jo <hj903.jo@samsung.com>
Wed, 2 Sep 2015 07:06:26 +0000 (16:06 +0900)
committerHyojung Jo <hj903.jo@samsung.com>
Wed, 2 Sep 2015 07:09:40 +0000 (16:09 +0900)
Change-Id: If8a680e336d4f1d0691ad49ff78a830b07c87106
Signed-off-by: Hyojung Jo <hj903.jo@samsung.com>
include/define.h
include/utils.h
res/widget/ctxpopup.edc
src/utils.c
src/view/view_action_menu.c
src/view/view_base.c

index 14707af..7b6f1e8 100644 (file)
@@ -51,7 +51,7 @@
 #define STYLE_MENU_BTN "style.menu.button"
 #define STYLE_SORT_BTN "style.sort.button"
 #define STYLE_OPTION_BTN "style.option.button"
-#define STYLE_SORT_CTXPOPUP "style.sort.ctxpopup"
+#define STYLE_CTXPOPUP "style.ctxpopup"
 #define STYLE_MYAPP "style.myapp"
 #define STYLE_FAVORITE "style.favorite"
 #define STYLE_LIVETV_BTN "style.livetv.button"
 #define SIZE_STR 1024
 #define SIZE_MENU_BOX_PAD_H (40 + 40)
 #define SIZE_MENU_BOX_PAD_V 0
-#define SIZE_SORT_BOX_PAD_H 0
-#define SIZE_SORT_BOX_PAD_V 0
 #define SIZE_ICON_MAX 100
 #define SIZE_ACTION_TABLE_BORDER 0
 #define SIZE_COL_MAX 4
index c71f59c..0d4aaf5 100644 (file)
@@ -17,6 +17,8 @@
 #ifndef __AIR_APPS_UTILS_H__
 #define __AIR_APPS_UTILS_H__
 
+#include <inputmgr.h>
+
 Evas_Object *utils_add_window(const char *name);
 Evas_Object *utils_add_layout(Evas_Object *parent, const char *group);
 Evas_Object *utils_add_box(Evas_Object *parent, const char *part,
@@ -33,6 +35,8 @@ Evas_Object *utils_add_notify(Evas_Object *parent, const char *text,
                int timeout);
 Evas_Object *utils_add_popup(Evas_Object *parent, const char *style,
                const char *popup_title, const char *popup_text);
+Evas_Object *utils_add_ctxpopup(Evas_Object *parent, int opt_size,
+               const char **opt_text, input_handler *opt_handler, void *data);
 bool utils_launch_app(const char *appid);
 bool utils_uninstall_app(const char *pkgid, const char *pkgtype);
 
index c3b4517..485b5ee 100644 (file)
@@ -1,5 +1,5 @@
 group {
-       name, "elm/ctxpopup/base/style.sort.ctxpopup";
+       name, "elm/ctxpopup/base/style.ctxpopup";
        data.item, "focus_hightlight" "on";
        parts {
                part {
index 804ff87..e42b957 100644 (file)
@@ -273,6 +273,59 @@ Evas_Object *utils_add_popup(Evas_Object *parent, const char *style,
        return popup;
 }
 
+Evas_Object *utils_add_ctxpopup(Evas_Object *parent, int opt_size,
+               const char **opt_text, input_handler *opt_handler, void *data)
+{
+       Evas_Object *ctxpopup, *box, *btn = NULL, *firstbtn = NULL;
+       int i;
+
+       if (!parent || opt_size <= 0 || !opt_text) {
+               _ERR("Invalid argument.");
+               return NULL;
+       }
+
+       ctxpopup = elm_ctxpopup_add(parent);
+       if (!ctxpopup) {
+               _ERR("elm_ctxpopup_add failed.");
+               return NULL;
+       }
+
+       box = utils_add_box(ctxpopup, NULL, EINA_FALSE, 0, 0);
+       if (!box) {
+               _ERR("Add box failed.");
+               evas_object_del(ctxpopup);
+               return NULL;
+       }
+
+       elm_object_style_set(ctxpopup, STYLE_CTXPOPUP);
+       elm_object_content_set(ctxpopup, box);
+       elm_ctxpopup_direction_priority_set(ctxpopup, 0, 0, 0, 0);
+       evas_object_show(ctxpopup);
+
+       for (i = 0; i < opt_size; i++) {
+               btn = utils_add_button(box, NULL, opt_text[i],
+                               STYLE_OPTION_BTN);
+               if (!btn) {
+                       _ERR("Add button failed.");
+                       evas_object_del(ctxpopup);
+                       return NULL;
+               }
+
+               elm_box_pack_end(box, btn);
+
+               if (opt_handler)
+                       inputmgr_add_callback(btn, i, opt_handler, data);
+
+               if (i == 0)
+                       firstbtn = btn;
+       }
+
+       elm_object_focus_next_object_set(firstbtn, btn, ELM_FOCUS_UP);
+       elm_object_focus_next_object_set(btn, firstbtn, ELM_FOCUS_DOWN);
+
+       return ctxpopup;
+}
+
 bool utils_launch_app(const char *appid)
 {
        app_control_h app_ctrl;
index 6af16a6..cc84802 100644 (file)
@@ -364,7 +364,7 @@ static bool _draw_livetv_area(struct _priv *priv)
        return true;
 }
 
-void _set_action_state(int idx, Evas_Object *btn, struct _priv *priv)
+static void _set_action_state(int idx, Evas_Object *btn, struct _priv *priv)
 {
        char *pkgtype;
        bool isfavorite;
index 180ebea..f83d65f 100644 (file)
@@ -360,59 +360,24 @@ static input_handler _option_input_handler = {
 
 static bool _draw_sort_option(struct _priv *priv)
 {
-       Evas_Object *ctxpopup, *box, *btn, *firstbtn;
+       Evas_Object *ctxpopup;
        Evas_Coord x, y, w, h;
-       int i;
 
        elm_object_signal_emit(priv->sort_btn, SIG_SELECTED, SRC_SORT_BTN);
 
-       ctxpopup = elm_ctxpopup_add(priv->base);
+       ctxpopup = utils_add_ctxpopup(priv->base, SORT_COUNT, str_sort,
+                       &_option_input_handler, priv);
        if (!ctxpopup) {
-               _ERR("elm_ctxpopup_add failed.");
-               return false;
-       }
-
-       box = utils_add_box(ctxpopup, NULL, EINA_FALSE,
-                       SIZE_SORT_BOX_PAD_H, SIZE_SORT_BOX_PAD_V);
-       if (!box) {
-               _ERR("elm_box_add failed.");
-               evas_object_del(ctxpopup);
+               _ERR("Add ctxpopup failed.");
                return false;
        }
 
-       elm_object_style_set(ctxpopup, STYLE_SORT_CTXPOPUP);
-       elm_object_content_set(ctxpopup, box);
-
-       elm_ctxpopup_direction_priority_set(ctxpopup, 0, 0, 0, 0);
        evas_object_geometry_get(priv->sort_btn, &x, &y, &w, &h);
        evas_object_move(ctxpopup, (x + w / 2) * elm_config_scale_get(),
                        y * elm_config_scale_get());
-       evas_object_show(ctxpopup);
 
        priv->sort_popup = ctxpopup;
 
-       for (i = 0; i < SORT_COUNT; i++) {
-               btn = utils_add_button(box, NULL, str_sort[i],
-                               STYLE_OPTION_BTN);
-               if (!btn) {
-                       _ERR("Add button failed.");
-                       evas_object_del(ctxpopup);
-                       return false;
-               }
-
-               elm_box_pack_end(box, btn);
-
-               inputmgr_add_callback(btn, i, &_option_input_handler, priv);
-
-               if (i == 0)
-                       firstbtn = btn;
-       }
-
-       if (firstbtn && btn) {
-               elm_object_focus_next_object_set(firstbtn, btn, ELM_FOCUS_UP);
-               elm_object_focus_next_object_set(btn, firstbtn, ELM_FOCUS_DOWN);
-       }
-
        return true;
 }