From 051702759c65ba4343b5ba43f239091eee736191 Mon Sep 17 00:00:00 2001 From: Soohye Shin Date: Mon, 13 Jul 2015 21:27:27 +0900 Subject: add photo viewer popup when gengrid item is selected - modify gengrid edc to apply focus_highlight - add elm_win_focus_highlight_enable to display focus_highlight of gengrid when photo_viewer is shown/hidden Change-Id: I023fa663f8ee979362410defcdcd9c5dc1e892bc Signed-off-by: Soohye Shin --- src/view/view_photo.c | 167 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 159 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/view/view_photo.c b/src/view/view_photo.c index fa4c64d..f81be73 100644 --- a/src/view/view_photo.c +++ b/src/view/view_photo.c @@ -32,11 +32,20 @@ struct _priv { Evas_Object *base; Evas_Object *grid; Evas_Object *ly; + Evas_Object *popup; Elm_Gengrid_Item_Class *grid_ic; + Eina_List *plist; + Elm_Object_Item *cur; struct datamgr *dm; }; +static void _cancel_key_down(int id, void *data, Evas *e, Evas_Object *obj, + Evas_Event_Key_Down *ev); + +static void _done_key_down(int id, void *data, Evas *e, Evas_Object *obj, + Evas_Event_Key_Down *ev); + static Evas_Object *_create(Evas_Object *win, void *data) { struct _priv *priv; @@ -152,9 +161,19 @@ static Evas_Object *_add_photo_grid(struct _priv *priv) static Evas_Object *_get_grid_content(void *data, Evas_Object *obj, const char *part) { - /* It should be implemented later */ + struct datamgr_item *di = data; + Evas_Object *img = NULL; + + if (!strcmp(part, PART_SWALLOW_ICON)) { + img = utils_add_icon(obj, di->icon, NULL); + if (!img) { + _ERR("failed to add image"); + return NULL; + } + elm_image_fill_outside_set(img, EINA_TRUE); + } - return NULL; + return img; } static void _del_content(void *data, Evas_Object *obj) @@ -162,9 +181,128 @@ static void _del_content(void *data, Evas_Object *obj) /* It should be implemented later */ } -static bool _add_photo_item(struct _priv *priv, Evas_Object *grid) +static void _delete_popup(struct _priv *priv, input_handler *handler, + Evas_Object *obj) +{ + inputmgr_remove_callback(obj, handler); + evas_object_del(priv->popup); + priv->popup = NULL; +} + +static input_handler cancel_handler = { + .key_down = _cancel_key_down +}; + +static void _cancel_key_down(int id, void *data, Evas *e, Evas_Object *obj, + Evas_Event_Key_Down *ev) +{ + struct _priv *priv = data; + + if (!strcmp(ev->keyname, KEY_ENTER) || + !strcmp(ev->keyname, KEY_ENTER_REMOTE) || + !strcmp(ev->keyname, KEY_BACK) || + !strcmp(ev->keyname, KEY_BACK_REMOTE)) { + _delete_popup(priv, &cancel_handler, obj); + elm_object_focus_allow_set(priv->grid, EINA_TRUE); + elm_object_focus_set(priv->grid, EINA_TRUE); + } +} + +static input_handler done_handler = { + .key_down = _done_key_down +}; + +static void _done_key_down(int id, void *data, Evas *e, Evas_Object *obj, + Evas_Event_Key_Down *ev) +{ + struct _priv *priv = data; + + if (!strcmp(ev->keyname, KEY_ENTER) || + !strcmp(ev->keyname, KEY_ENTER_REMOTE)) { + _delete_popup(priv, &done_handler, obj); + elm_object_focus_allow_set(priv->grid, EINA_TRUE); + elm_object_focus_set(priv->grid, EINA_TRUE); + } else if (!strcmp(ev->keyname, KEY_BACK) || + !strcmp(ev->keyname, KEY_BACK_REMOTE)) { + _delete_popup(priv, &done_handler, obj); + elm_object_focus_allow_set(priv->grid, EINA_TRUE); + elm_object_focus_set(priv->grid, EINA_TRUE); + } +} + +static void _add_viewer_popup(struct _priv *priv, char *file) +{ + Evas_Object *popup, *ly, *cancel_btn, *done_btn, *img; + + popup = utils_add_popup(priv->base, NULL, NULL); + if (!popup) { + _ERR("failed to add popup"); + return; + } + + ly = utils_add_layout(popup, GRP_PHOTO_VIEWER, false, + PART_SWALLOW_CONTENT); + if (!ly) { + _ERR("failed to add layout"); + evas_object_del(popup); + return; + } + + cancel_btn = utils_add_button(ly, MESSAGE_CANCEL, + PART_PHOTO_VIEWER_CANCEL); + if (!cancel_btn) { + _ERR("failed to add cancel button"); + evas_object_del(popup); + return; + } + inputmgr_add_callback(cancel_btn, 0, &cancel_handler, priv); + + done_btn = utils_add_button(ly, MESSAGE_DONE, PART_PHOTO_VIEWER_DONE); + if (!done_btn) { + _ERR("failed to add done button"); + evas_object_del(popup); + return; + } + inputmgr_add_callback(done_btn, 0, &done_handler, priv); + + elm_object_focus_set(cancel_btn, EINA_TRUE); + + img = utils_add_icon(ly, file, PART_PHOTO_VIEWER); + if (!img) { + _ERR("failed to add icon"); + evas_object_del(popup); + return; + } + elm_image_fill_outside_set(img, EINA_TRUE); + + elm_object_focus_set(cancel_btn, EINA_TRUE); + priv->popup = popup; +} + +static void _select_item(void *data, Evas_Object *obj, void *ei) +{ + struct datamgr_item *di; + struct _priv *priv = data; + + di = elm_object_item_data_get(ei); + if (!di) { + _ERR("failed to get data"); + return; + } + + elm_object_focus_allow_set(priv->grid, EINA_FALSE); + _add_viewer_popup(priv, di->focus_icon); + + priv->cur = ei; +} + +static bool _add_photo_item(struct _priv *priv, Evas_Object *grid, + Eina_List *dlist) { Elm_Gengrid_Item_Class *ic; + Elm_Object_Item *item; + Eina_List *l; + struct datamgr_item *di; elm_gengrid_clear(grid); @@ -180,8 +318,17 @@ static bool _add_photo_item(struct _priv *priv, Evas_Object *grid) ic->func.state_get = NULL; ic->func.del = _del_content; - /* It should be implemented later */ + EINA_LIST_FOREACH(dlist, l, di) { + item = elm_gengrid_item_append(grid, ic, di, + _select_item, priv); + if (!item) + continue; + + elm_object_item_data_set(item, di); + priv->plist = eina_list_append(priv->plist, item); + } + priv->cur = elm_gengrid_first_item_get(grid); priv->grid_ic = ic; return true; @@ -189,11 +336,11 @@ static bool _add_photo_item(struct _priv *priv, Evas_Object *grid) static void _load_photo(struct _priv *priv) { - Eina_List *list; + Eina_List *dlist; Evas_Object *grid; - list = datamgr_get_items(priv->dm); - if (!list) { + dlist = datamgr_get_items(priv->dm); + if (!dlist) { _load_no_content(priv); return; } @@ -204,7 +351,7 @@ static void _load_photo(struct _priv *priv) return; } - if (!_add_photo_item(priv, grid)) { + if (!_add_photo_item(priv, grid, dlist)) { _ERR("failed to add photo item"); evas_object_del(grid); _load_no_content(priv); @@ -225,12 +372,15 @@ static void _show(void *data) priv = data; + elm_win_focus_highlight_enabled_set(priv->win, EINA_TRUE); evas_object_show(priv->base); _load_photo(priv); if (priv->ly) elm_object_focus_set(priv->ly, EINA_TRUE); + else + elm_object_focus_set(priv->grid, EINA_TRUE); } static void _hide(void *data) @@ -255,6 +405,7 @@ static void _hide(void *data) } evas_object_hide(priv->base); + elm_win_focus_highlight_enabled_set(priv->win, EINA_FALSE); } static void _destroy(void *data) -- cgit v1.2.3