From 9cc45f0548134cd36dc5746aeb1e1940ea9d8999 Mon Sep 17 00:00:00 2001 From: Jaeun Choi Date: Tue, 15 Apr 2014 14:52:06 +0900 Subject: [PATCH] map: apply key binding Summary: This patch applies key binding to elm_map. Test Plan: None Reviewers: Hermet, raster Reviewed By: Hermet Differential Revision: https://phab.enlightenment.org/D733 --- config/default/base.src | 89 ++++++++++++++++++++++++++++++++++++++++++++++++ config/mobile/base.src | 89 ++++++++++++++++++++++++++++++++++++++++++++++++ config/standard/base.src | 89 ++++++++++++++++++++++++++++++++++++++++++++++++ src/lib/elm_map.c | 74 ++++++++++++++++++++++++++-------------- 4 files changed, 315 insertions(+), 26 deletions(-) diff --git a/config/default/base.src b/config/default/base.src index 0de169c..1de5664 100644 --- a/config/default/base.src +++ b/config/default/base.src @@ -947,6 +947,95 @@ group "Elm_Config" struct { } } group "Elm_Config_Bindings_Widget" struct { + value "name" string: "Elm_Map"; + group "key_bindings" list { + group "Elm_Config_Binding_Key" struct { + value "context" int: 0; + value "key" string: "Left"; + value "action" string: "move"; + value "params" string: "left"; + } + group "Elm_Config_Binding_Key" struct { + value "context" int: 0; + value "key" string: "KP_Left"; + value "action" string: "move"; + value "params" string: "left"; + } + group "Elm_Config_Binding_Key" struct { + value "context" int: 0; + value "key" string: "Right"; + value "action" string: "move"; + value "params" string: "right"; + } + group "Elm_Config_Binding_Key" struct { + value "context" int: 0; + value "key" string: "KP_Right"; + value "action" string: "move"; + value "params" string: "right"; + } + group "Elm_Config_Binding_Key" struct { + value "context" int: 0; + value "key" string: "Up"; + value "action" string: "move"; + value "params" string: "up"; + } + group "Elm_Config_Binding_Key" struct { + value "context" int: 0; + value "key" string: "KP_Up"; + value "action" string: "move"; + value "params" string: "up"; + } + group "Elm_Config_Binding_Key" struct { + value "context" int: 0; + value "key" string: "Down"; + value "action" string: "move"; + value "params" string: "down"; + } + group "Elm_Config_Binding_Key" struct { + value "context" int: 0; + value "key" string: "KP_Down"; + value "action" string: "move"; + value "params" string: "down"; + } + group "Elm_Config_Binding_Key" struct { + value "context" int: 0; + value "key" string: "Prior"; + value "action" string: "move"; + value "params" string: "prior"; + } + group "Elm_Config_Binding_Key" struct { + value "context" int: 0; + value "key" string: "KP_Prior"; + value "action" string: "move"; + value "params" string: "prior"; + } + group "Elm_Config_Binding_Key" struct { + value "context" int: 0; + value "key" string: "Next"; + value "action" string: "move"; + value "params" string: "next"; + } + group "Elm_Config_Binding_Key" struct { + value "context" int: 0; + value "key" string: "KP_Next"; + value "action" string: "move"; + value "params" string: "next"; + } + group "Elm_Config_Binding_Key" struct { + value "context" int: 0; + value "key" string: "KP_Add"; + value "action" string: "zoom"; + value "params" string: "in"; + } + group "Elm_Config_Binding_Key" struct { + value "context" int: 0; + value "key" string: "KP_Subtract"; + value "action" string: "zoom"; + value "params" string: "out"; + } + } + } + group "Elm_Config_Bindings_Widget" struct { value "name" string: "Elm_Panel"; group "key_bindings" list { group "Elm_Config_Binding_Key" struct { diff --git a/config/mobile/base.src b/config/mobile/base.src index a308a28..a98745f 100644 --- a/config/mobile/base.src +++ b/config/mobile/base.src @@ -951,6 +951,95 @@ group "Elm_Config" struct { } } group "Elm_Config_Bindings_Widget" struct { + value "name" string: "Elm_Map"; + group "key_bindings" list { + group "Elm_Config_Binding_Key" struct { + value "context" int: 0; + value "key" string: "Left"; + value "action" string: "move"; + value "params" string: "left"; + } + group "Elm_Config_Binding_Key" struct { + value "context" int: 0; + value "key" string: "KP_Left"; + value "action" string: "move"; + value "params" string: "left"; + } + group "Elm_Config_Binding_Key" struct { + value "context" int: 0; + value "key" string: "Right"; + value "action" string: "move"; + value "params" string: "right"; + } + group "Elm_Config_Binding_Key" struct { + value "context" int: 0; + value "key" string: "KP_Right"; + value "action" string: "move"; + value "params" string: "right"; + } + group "Elm_Config_Binding_Key" struct { + value "context" int: 0; + value "key" string: "Up"; + value "action" string: "move"; + value "params" string: "up"; + } + group "Elm_Config_Binding_Key" struct { + value "context" int: 0; + value "key" string: "KP_Up"; + value "action" string: "move"; + value "params" string: "up"; + } + group "Elm_Config_Binding_Key" struct { + value "context" int: 0; + value "key" string: "Down"; + value "action" string: "move"; + value "params" string: "down"; + } + group "Elm_Config_Binding_Key" struct { + value "context" int: 0; + value "key" string: "KP_Down"; + value "action" string: "move"; + value "params" string: "down"; + } + group "Elm_Config_Binding_Key" struct { + value "context" int: 0; + value "key" string: "Prior"; + value "action" string: "move"; + value "params" string: "prior"; + } + group "Elm_Config_Binding_Key" struct { + value "context" int: 0; + value "key" string: "KP_Prior"; + value "action" string: "move"; + value "params" string: "prior"; + } + group "Elm_Config_Binding_Key" struct { + value "context" int: 0; + value "key" string: "Next"; + value "action" string: "move"; + value "params" string: "next"; + } + group "Elm_Config_Binding_Key" struct { + value "context" int: 0; + value "key" string: "KP_Next"; + value "action" string: "move"; + value "params" string: "next"; + } + group "Elm_Config_Binding_Key" struct { + value "context" int: 0; + value "key" string: "KP_Add"; + value "action" string: "zoom"; + value "params" string: "in"; + } + group "Elm_Config_Binding_Key" struct { + value "context" int: 0; + value "key" string: "KP_Subtract"; + value "action" string: "zoom"; + value "params" string: "out"; + } + } + } + group "Elm_Config_Bindings_Widget" struct { value "name" string: "Elm_Panel"; group "key_bindings" list { group "Elm_Config_Binding_Key" struct { diff --git a/config/standard/base.src b/config/standard/base.src index d44ebf4..bdcdd97 100644 --- a/config/standard/base.src +++ b/config/standard/base.src @@ -948,6 +948,95 @@ group "Elm_Config" struct { } } group "Elm_Config_Bindings_Widget" struct { + value "name" string: "Elm_Map"; + group "key_bindings" list { + group "Elm_Config_Binding_Key" struct { + value "context" int: 0; + value "key" string: "Left"; + value "action" string: "move"; + value "params" string: "left"; + } + group "Elm_Config_Binding_Key" struct { + value "context" int: 0; + value "key" string: "KP_Left"; + value "action" string: "move"; + value "params" string: "left"; + } + group "Elm_Config_Binding_Key" struct { + value "context" int: 0; + value "key" string: "Right"; + value "action" string: "move"; + value "params" string: "right"; + } + group "Elm_Config_Binding_Key" struct { + value "context" int: 0; + value "key" string: "KP_Right"; + value "action" string: "move"; + value "params" string: "right"; + } + group "Elm_Config_Binding_Key" struct { + value "context" int: 0; + value "key" string: "Up"; + value "action" string: "move"; + value "params" string: "up"; + } + group "Elm_Config_Binding_Key" struct { + value "context" int: 0; + value "key" string: "KP_Up"; + value "action" string: "move"; + value "params" string: "up"; + } + group "Elm_Config_Binding_Key" struct { + value "context" int: 0; + value "key" string: "Down"; + value "action" string: "move"; + value "params" string: "down"; + } + group "Elm_Config_Binding_Key" struct { + value "context" int: 0; + value "key" string: "KP_Down"; + value "action" string: "move"; + value "params" string: "down"; + } + group "Elm_Config_Binding_Key" struct { + value "context" int: 0; + value "key" string: "Prior"; + value "action" string: "move"; + value "params" string: "prior"; + } + group "Elm_Config_Binding_Key" struct { + value "context" int: 0; + value "key" string: "KP_Prior"; + value "action" string: "move"; + value "params" string: "prior"; + } + group "Elm_Config_Binding_Key" struct { + value "context" int: 0; + value "key" string: "Next"; + value "action" string: "move"; + value "params" string: "next"; + } + group "Elm_Config_Binding_Key" struct { + value "context" int: 0; + value "key" string: "KP_Next"; + value "action" string: "move"; + value "params" string: "next"; + } + group "Elm_Config_Binding_Key" struct { + value "context" int: 0; + value "key" string: "KP_Add"; + value "action" string: "zoom"; + value "params" string: "in"; + } + group "Elm_Config_Binding_Key" struct { + value "context" int: 0; + value "key" string: "KP_Subtract"; + value "action" string: "zoom"; + value "params" string: "out"; + } + } + } + group "Elm_Config_Bindings_Widget" struct { value "name" string: "Elm_Panel"; group "key_bindings" list { group "Elm_Config_Binding_Key" struct { diff --git a/src/lib/elm_map.c b/src/lib/elm_map.c index d784137..1b89bae 100644 --- a/src/lib/elm_map.c +++ b/src/lib/elm_map.c @@ -48,6 +48,15 @@ #define NOMINATIM_ATTR_LAT "lat" #define NOMINATIM_ATTR_ADDRESS "display_name" +static Eina_Bool _key_action_move(Evas_Object *obj, const char *params); +static Eina_Bool _key_action_zoom(Evas_Object *obj, const char *params); + +static const Elm_Action key_actions[] = { + {"move", _key_action_move}, + {"zoom", _key_action_zoom}, + {NULL, NULL} +}; + static char * _mapnik_url_cb(const Evas_Object *obj EINA_UNUSED, int x, @@ -3805,77 +3814,90 @@ _elm_map_elm_widget_theme_apply(Eo *obj, Elm_Map_Data *sd EINA_UNUSED) return EINA_TRUE; } -EOLIAN static Eina_Bool -_elm_map_elm_widget_event(Eo *obj, Elm_Map_Data *sd, Evas_Object *src, Evas_Callback_Type type, void *event_info) +static Eina_Bool +_key_action_move(Evas_Object *obj, const char *params) { - (void) src; - Evas_Event_Key_Down *ev = event_info; + const char *dir = params; Evas_Coord vh; Evas_Coord x, y; Evas_Coord step_x, step_y, page_x, page_y; - if (elm_widget_disabled_get(obj)) return EINA_FALSE; - if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE; - if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE; - eo_do(obj, elm_interface_scrollable_content_pos_get(&x, &y), elm_interface_scrollable_step_size_get(&step_x, &step_y), elm_interface_scrollable_page_size_get(&page_x, &page_y), elm_interface_scrollable_content_viewport_size_get(NULL, &vh)); - if ((!strcmp(ev->key, "Left")) || - ((!strcmp(ev->key, "KP_Left")) && (!ev->string))) + if (!strcmp(dir, "left")) { x -= step_x; } - else if ((!strcmp(ev->key, "Right")) || - ((!strcmp(ev->key, "KP_Right")) && (!ev->string))) + else if (!strcmp(dir, "right")) { x += step_x; } - else if ((!strcmp(ev->key, "Up")) || - ((!strcmp(ev->key, "KP_Up")) && (!ev->string))) + else if (!strcmp(dir, "up")) { y -= step_y; } - else if ((!strcmp(ev->key, "Down")) || - ((!strcmp(ev->key, "KP_Down")) && (!ev->string))) + else if (!strcmp(dir, "down")) { y += step_y; } - else if ((!strcmp(ev->key, "Prior")) || - ((!strcmp(ev->key, "KP_Prior")) && (!ev->string))) + else if (!strcmp(dir, "prior")) { if (page_y < 0) y -= -(page_y * vh) / 100; else y -= page_y; } - else if ((!strcmp(ev->key, "Next")) || - ((!strcmp(ev->key, "KP_Next")) && (!ev->string))) + else if (!strcmp(dir, "next")) { if (page_y < 0) y += -(page_y * vh) / 100; else y += page_y; } - else if (!strcmp(ev->key, "KP_Add")) + else return EINA_FALSE; + + eo_do(obj, elm_interface_scrollable_content_pos_set(x, y, EINA_TRUE)); + return EINA_TRUE; +} + +static Eina_Bool +_key_action_zoom(Evas_Object *obj, const char *params) +{ + ELM_MAP_DATA_GET(obj, sd); + const char *dir = params; + + if (!strcmp(dir, "in")) { _zoom_with_animation(sd, sd->zoom + 1, 10); - return EINA_TRUE; } - else if (!strcmp(ev->key, "KP_Subtract")) + else if (!strcmp(dir, "out")) { _zoom_with_animation(sd, sd->zoom - 1, 10); - return EINA_TRUE; } else return EINA_FALSE; - ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD; - eo_do(obj, elm_interface_scrollable_content_pos_set(x, y, EINA_TRUE)); + return EINA_TRUE; +} + +EOLIAN static Eina_Bool +_elm_map_elm_widget_event(Eo *obj, Elm_Map_Data *sd EINA_UNUSED, Evas_Object *src, Evas_Callback_Type type, void *event_info) +{ + (void) src; + Evas_Event_Key_Down *ev = event_info; + if (elm_widget_disabled_get(obj)) return EINA_FALSE; + if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE; + if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE; + + if (!_elm_config_key_binding_call(obj, ev, key_actions)) + return EINA_FALSE; + + ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD; return EINA_TRUE; } -- 2.7.4