#include "datamgr.h"
#include "utils.h"
+enum input_handler_type {
+ INPUT_HANDLER_TYPE_BASE,
+ INPUT_HANDLER_TYPE_EO,
+ INPUT_HANDLER_TYPE_DOWN
+};
+
struct _priv {
Evas_Object *win;
Evas_Object *base;
+ Evas_Object *down;
Eina_List *list;
struct datamgr *dm;
struct _priv *priv;
};
-static bool _add_navigations(Evas_Object *base)
+static void _focused(int id, void *data, Evas_Object *obj,
+ Elm_Object_Item *item)
{
- Evas_Object *ly;
+ struct _priv *priv;
+ struct bar_item *bi;
- if (!base) {
- _ERR("Invalid argument");
- return false;
+ switch (id) {
+ case INPUT_HANDLER_TYPE_EO:
+ if (!data) {
+ _ERR("Invalid argument");
+ return;
+ }
+ bi = data;
+ priv = bi->priv;
+ priv->foc = bi;
+ /* fallthrough */
+ case INPUT_HANDLER_TYPE_DOWN:
+ elm_object_signal_emit(obj, SIG_FOCUS, SRC_PROG);
+ break;
+ default:
+ return;
}
+}
- ly = utils_add_layout(base, GRP_HOME_DOWN_ARROW, true,
- PART_HOME_DOWN_ARROW);
- if (!ly) {
- _ERR("failed to add layout");
- return false;
+static void _unfocused(int id, void *data, Evas_Object *obj,
+ Elm_Object_Item *item)
+{
+ switch (id) {
+ case INPUT_HANDLER_TYPE_EO:
+ case INPUT_HANDLER_TYPE_DOWN:
+ elm_object_signal_emit(obj, SIG_UNFOCUS, SRC_PROG);
+ break;
+ default:
+ return;
}
-
- return true;
}
-static void _focused(int id, void *data, Evas_Object *obj,
- Elm_Object_Item *item)
+static void _key_down(int id, void *data, Evas *e, Evas_Object *obj,
+ Evas_Event_Key_Down *ev)
{
struct _priv *priv;
- struct bar_item *bi;
+
+ if (id != INPUT_HANDLER_TYPE_BASE)
+ return;
if (!data) {
_ERR("Invalid argument");
return;
}
- bi = data;
- priv = bi->priv;
- priv->foc = bi;
+ priv = data;
- elm_object_signal_emit(obj, SIG_FOCUS, SRC_PROG);
+ if (!strcmp(ev->keyname, KEY_DOWN)) {
+ viewmgr_push_view(VIEW_RECENT);
+ } else if (!strcmp(ev->keyname, KEY_ENTER) ||
+ !strcmp(ev->keyname, KEY_ENTER_REMOTE)) {
+ datamgr_select_item(priv->dm, priv->foc->di);
+ } else if (!strcmp(ev->keyname, KEY_BACK) ||
+ !strcmp(ev->keyname, KEY_BACK_REMOTE)) {
+ /* It should be implemented later */
+ }
}
-static void _unfocused(int id, void *data, Evas_Object *obj,
- Elm_Object_Item *item)
+static void _mouse_down(int id, void *data, Evas *e, Evas_Object *obj,
+ Evas_Event_Mouse_Down *ev)
{
- elm_object_signal_emit(obj, SIG_UNFOCUS, SRC_PROG);
+ struct _priv *priv;
+ struct bar_item *bi;
+
+ switch (id) {
+ case INPUT_HANDLER_TYPE_EO:
+ if (!data)
+ return;
+
+ bi = data;
+ priv = bi->priv;
+ datamgr_select_item(priv->dm, priv->foc->di);
+ break;
+ case INPUT_HANDLER_TYPE_DOWN:
+ viewmgr_push_view(VIEW_RECENT);
+ break;
+ default:
+ return;
+ }
}
-static input_handler eo_handler = {
+static input_handler handler = {
.focused = _focused,
- .unfocused = _unfocused
+ .unfocused = _unfocused,
+ .key_down = _key_down,
+ .mouse_down = _mouse_down
};
+static bool _add_navigations(struct _priv *priv, Evas_Object *base)
+{
+ Evas_Object *ly;
+
+ ly = utils_add_layout(base, GRP_HOME_DOWN_ARROW, true,
+ PART_HOME_DOWN_ARROW);
+ if (!ly) {
+ _ERR("failed to add layout");
+ return false;
+ }
+
+ inputmgr_add_callback(ly, INPUT_HANDLER_TYPE_DOWN, &handler, priv);
+ priv->down = ly;
+
+ return true;
+}
+
static struct bar_item *_pack_bar_item(struct _priv *priv, Evas_Object *box,
struct datamgr_item *di)
{
if (!bg)
goto err;
- inputmgr_add_callback(eo, 0, &eo_handler, bi);
+ inputmgr_add_callback(eo, INPUT_HANDLER_TYPE_EO, &handler, bi);
elm_box_pack_end(box, eo);
evas_object_show(eo);
struct bar_item *bi;
struct datamgr_item *di;
- if (!priv || !base) {
- _ERR("Invalid argument");
- return false;
- }
-
scr = utils_add_scroller(base);
if (!scr) {
_ERR("failed to add scroller");
static bool _add_home(struct _priv *priv, Evas_Object *base)
{
- if (!priv || !base) {
- _ERR("Invalid argument");
- return false;
- }
- if (!_add_navigations(base)) {
+ if (!_add_navigations(priv, base)) {
_ERR("failed to add navigations");
return false;
}
return true;
}
-static void _key_down(int id, void *data, Evas *e, Evas_Object *obj,
- Evas_Event_Key_Down *ev)
-{
- struct _priv *priv;
-
- if (!data) {
- _ERR("Invalid argument");
- return;
- }
-
- priv = data;
-
- if (!strcmp(ev->keyname, KEY_DOWN)) {
- viewmgr_push_view(VIEW_RECENT);
- } else if (!strcmp(ev->keyname, KEY_ENTER) ||
- !strcmp(ev->keyname, KEY_ENTER_REMOTE)) {
- datamgr_select_item(priv->dm, priv->foc->di);
- } else if (!strcmp(ev->keyname, KEY_BACK) ||
- !strcmp(ev->keyname, KEY_BACK_REMOTE)) {
- /* It should be implemented later */
- }
-}
-
-static input_handler base_handler = {
- .key_down = _key_down
-};
-
static Evas_Object *_create(Evas_Object *win, void *data)
{
struct _priv *priv;
struct datamgr *dm;
Evas_Object *base;
- if (!win) {
- _ERR("Invalid argument");
- return NULL;
- }
-
priv = calloc(1, sizeof(*priv));
if (!priv) {
_ERR("failed to calloc priv");
}
viewmgr_set_view_data(VIEW_HOME, priv);
- inputmgr_add_callback(base, 0, &base_handler, priv);
+ inputmgr_add_callback(base, INPUT_HANDLER_TYPE_BASE, &handler, priv);
return base;
}
priv = data;
EINA_LIST_FREE(priv->list, bi) {
- inputmgr_remove_callback(bi->eo, &eo_handler);
+ inputmgr_remove_callback(bi->eo, &handler);
evas_object_del(bi->eo);
free(bi);
}
datamgr_fini(priv->dm);
- inputmgr_remove_callback(priv->base, &base_handler);
+ inputmgr_remove_callback(priv->base, &handler);
+ inputmgr_remove_callback(priv->down, &handler);
evas_object_del(priv->base);
priv->list = NULL;