[GUI] Focus chain added to the clock view. 07/124807/2
authorMichal Skorupinski <m.skorupinsk@samsung.com>
Tue, 11 Apr 2017 12:18:33 +0000 (14:18 +0200)
committerMichal Skorupinski <m.skorupinsk@samsung.com>
Wed, 12 Apr 2017 10:51:11 +0000 (12:51 +0200)
Change-Id: Idef9e1e3d2e2604e52ed7cf9917c85b7cfab4e04
Signed-off-by: Michal Skorupinski <m.skorupinsk@samsung.com>
res/widget/spinner.edc
src/view/system/view_clock.c

index 9a36d9e..1bdcd3c 100644 (file)
@@ -365,205 +365,205 @@ group { name: "elm/button/base/spinner/decrease/settings.datetime";
 }
 
 group { name: "elm/button/base/spinner/settings.datetime";
-   data.item: "focus_highlight" "on";
-   script {
-      public mouse_down = 0;
-      public multi_down = 0;
-   }
-   parts {
-      part { name: "bg";
-         type: SPACER;
-         scale: 1;
-         description { state: "default" 0.0;
-            min: WIDTH TEXT_HEIGHT;
-         }
-      }
-      part { name: "elm.text";
-         type: TEXT;
-         scale: 1;
-         description { state: "default" 0.0;
-            min: 0 TEXT_HEIGHT;
-            max: -1 TEXT_HEIGHT;
-            fixed: 1 1;
-            color: 0 0 0 255;
-            rel1.to: "bg";
-            rel2.to: "bg";
-            text {
-               font: "Tizen:style=Light";
-               size: 72;
-               text_class: "tizen";
-               ellipsis: -1.0;
-            }
-         }
-         description { state: "pressed" 0.0;
-            inherit: "default" 0.0 ;
-         }
-         description { state: "disabled" 0.0;
-            inherit: "default" 0.0 ;
-         }
-      }
-      part { name: "focus_image";
-         type: SPACER;
-         scale: 1;
-         description { state: "default" 0.0;
-            rel1.to: "bg";
-            rel2.to: "bg";
-         }
-         description { state: "focused" 0.0;
-            inherit: "default" 0.0;
-         }
-      }
-      part { name: "over";
-         type: RECT;
-         repeat_events: 1;
-         description { state: "default" 0.0;
-            color: 0 0 0 0;
-         }
-      }
-      part { name: "disabler";
-         type: RECT;
-         description { state: "default" 0.0;
-            color: 0 0 0 0;
-            visible: 0;
-         }
-         description { state: "disabled" 0.0;
-            inherit: "default" 0.0;
-            visible: 1;
-         }
-      }
-   }
-   programs {
-      program { name: "button_press";
-         signal: "mouse,down,1*";
-         source: "over";
-         script {
-            if ((get_int(multi_down) == 0) &&
-                (get_int(mouse_down) == 0)) {
-                  set_int(mouse_down, 1);
-                  run_program(PROGRAM:"button_press2");
-            }
-         }
-      }
-      program { name: "button_press2";
-         action: SIGNAL_EMIT "elm,action,press" "";
-         after: "action_pressed";
-      }
-      program { name: "button_unpress";
-         signal: "mouse,up,1*";
-         source: "over";
-         script {
-            if (get_int(mouse_down) == 1) {
-                  set_int(mouse_down, 0);
-                  run_program(PROGRAM:"button_unpress2");
-            }
-         }
-      }
-      program { name: "button_unpress2";
-         action: SIGNAL_EMIT "elm,action,unpress" "";
-         after: "action_unpressed";
-      }
-      program { name: "button_click";
-         signal: "mouse,clicked,1";
-         source: "over";
-         script {
-            if (get_int(multi_down) == 0) {
-              run_program(PROGRAM:"play_sound");
-              run_program(PROGRAM:"button_click2");
-            }
-         }
-      }
-      program { name: "play_sound";
-         action: RUN_PLUGIN "touch_sound";
-      }
-      program { name: "button_click2";
-         action: SIGNAL_EMIT "elm,action,click" "";
-      }
-      program { name: "action_pressed";
-         action: STATE_SET "pressed" 0.0;
-         target: "elm.text";
-      }
-      program { name: "action_unpressed";
-         action: STATE_SET "default" 0.0;
-         target: "elm.text";
-      }
-      program { name: "action_focus";
-         signal: "elm,action,focus_highlight,show";
-         source: "elm";
-         action: STATE_SET "focused" 0.0;
-         target: "focus_image";
-      }
-      program { name: "action_unfocus";
-         signal: "elm,action,focus_highlight,hide";
-         source: "elm";
-         action: STATE_SET "default" 0.0;
-         target: "focus_image";
-      }
-      program { name: "disable";
-         signal: "elm,state,disabled";
-         source: "elm";
-         action: STATE_SET "disabled" 0.0;
-         target: "disabler";
-         target: "elm.text";
-      }
-      program { name: "enable";
-         signal: "elm,state,enabled";
-         source: "elm";
-         action: STATE_SET "default" 0.0;
-         target: "disabler";
-         target: "elm.text";
-      }
-      program {
-         name: "multi_down";
-         signal: "elm,action,multi,down";
-         source: "elm";
-         script {
-            set_int(multi_down, 1);
-         }
-      }
-      program {
-         name: "multi_up";
-         signal: "elm,action,multi,up";
-         source: "elm";
-         script {
-            set_int(multi_down, 0);
-         }
-      }
-      program { name: "pass_event_enable";
-         signal: "elm,event,pass,enabled";
-         source: "elm";
-         script {
-            set_mouse_events(PART:"over", 0);
-            set_mouse_events(PART:"disabler", 0);
-         }
-      }
-      program { name: "pass_event_disable";
-         signal: "elm,event,pass,disabled";
-         source:"elm";
-         script {
-            set_mouse_events(PART:"over", 1);
-            set_mouse_events(PART:"disabler", 1);
-         }
-      }
-      program { name: "repeat_event_enable";
-         signal: "elm,event,repeat,enabled";
-         source: "elm";
-         script {
-            set_repeat_events(PART:"over", 1);
-            set_repeat_events(PART:"disabler", 1);
-         }
-      }
-      program { name: "repeat_event_disable";
-         signal: "elm,event,repeat,disabled";
-         source:"elm";
-         script {
-            set_repeat_events(PART:"over", 0);
-            set_repeat_events(PART:"disabler", 0);
-         }
-      }
-   }
+       script {
+               public mouse_down = 0;
+               public multi_down = 0;
+       }
+       parts {
+               part { name: "bg";
+                       type: SPACER;
+                       scale: 1;
+                       description { state: "default" 0.0;
+                               min: WIDTH TEXT_HEIGHT;
+                       }
+               }
+               part { name: "elm.text";
+                       type: TEXT;
+                       scale: 1;
+                       description { state: "default" 0.0;
+                               min: 0 TEXT_HEIGHT;
+                               max: -1 TEXT_HEIGHT;
+                               fixed: 1 1;
+                               color: 0 0 0 255;
+                               rel1.to: "bg";
+                               rel2.to: "bg";
+                               text {
+                                       font: "Tizen:style=Light";
+                                       size: 72;
+                                       text_class: "tizen";
+                                       ellipsis: -1.0;
+                               }
+                       }
+                       description { state: "pressed" 0.0;
+                               inherit: "default" 0.0 ;
+                       }
+                       description { state: "disabled" 0.0;
+                               inherit: "default" 0.0 ;
+                       }
+               }
+               part { name: "focus_image";
+                       type: RECT;
+                       scale: 1;
+                       description { state: "default" 0.0;
+                               rel1.to: "bg";
+                               rel2.to: "bg";
+                               color: 255 0 0 0;
+                       }
+                       description { state: "focused" 0.0;
+                               inherit: "default" 0.0;
+                               color: 255 0 0 32;
+                       }
+               }
+               part { name: "over";
+                       type: RECT;
+                       repeat_events: 1;
+                       description { state: "default" 0.0;
+                               color: 0 0 0 0;
+                       }
+               }
+               part { name: "disabler";
+                       type: RECT;
+                       description { state: "default" 0.0;
+                               color: 0 0 0 0;
+                               visible: 0;
+                       }
+                       description { state: "disabled" 0.0;
+                               inherit: "default" 0.0;
+                               visible: 1;
+                       }
+               }
+       }
+       programs {
+               program { name: "button_press";
+                       signal: "mouse,down,1*";
+                       source: "over";
+                       script {
+                               if ((get_int(multi_down) == 0) &&
+                                        (get_int(mouse_down) == 0)) {
+                                               set_int(mouse_down, 1);
+                                               run_program(PROGRAM:"button_press2");
+                               }
+                       }
+               }
+               program { name: "button_press2";
+                       action: SIGNAL_EMIT "elm,action,press" "";
+                       after: "action_pressed";
+               }
+               program { name: "button_unpress";
+                       signal: "mouse,up,1*";
+                       source: "over";
+                       script {
+                               if (get_int(mouse_down) == 1) {
+                                               set_int(mouse_down, 0);
+                                               run_program(PROGRAM:"button_unpress2");
+                               }
+                       }
+               }
+               program { name: "button_unpress2";
+                       action: SIGNAL_EMIT "elm,action,unpress" "";
+                       after: "action_unpressed";
+               }
+               program { name: "button_click";
+                       signal: "mouse,clicked,1";
+                       source: "over";
+                       script {
+                               if (get_int(multi_down) == 0) {
+                                 run_program(PROGRAM:"play_sound");
+                                 run_program(PROGRAM:"button_click2");
+                               }
+                       }
+               }
+               program { name: "play_sound";
+                       action: RUN_PLUGIN "touch_sound";
+               }
+               program { name: "button_click2";
+                       action: SIGNAL_EMIT "elm,action,click" "";
+               }
+               program { name: "action_pressed";
+                       action: STATE_SET "pressed" 0.0;
+                       target: "elm.text";
+               }
+               program { name: "action_unpressed";
+                       action: STATE_SET "default" 0.0;
+                       target: "elm.text";
+               }
+               program { name: "action_focus";
+                       signal: "elm,action,focus_highlight,show";
+                       source: "elm";
+                       action: STATE_SET "focused" 0.0;
+                       target: "focus_image";
+               }
+               program { name: "action_unfocus";
+                       signal: "elm,action,focus_highlight,hide";
+                       source: "elm";
+                       action: STATE_SET "default" 0.0;
+                       target: "focus_image";
+               }
+               program { name: "disable";
+                       signal: "elm,state,disabled";
+                       source: "elm";
+                       action: STATE_SET "disabled" 0.0;
+                       target: "disabler";
+                       target: "elm.text";
+               }
+               program { name: "enable";
+                       signal: "elm,state,enabled";
+                       source: "elm";
+                       action: STATE_SET "default" 0.0;
+                       target: "disabler";
+                       target: "elm.text";
+               }
+               program {
+                       name: "multi_down";
+                       signal: "elm,action,multi,down";
+                       source: "elm";
+                       script {
+                               set_int(multi_down, 1);
+                       }
+               }
+               program {
+                       name: "multi_up";
+                       signal: "elm,action,multi,up";
+                       source: "elm";
+                       script {
+                               set_int(multi_down, 0);
+                       }
+               }
+               program { name: "pass_event_enable";
+                       signal: "elm,event,pass,enabled";
+                       source: "elm";
+                       script {
+                               set_mouse_events(PART:"over", 0);
+                               set_mouse_events(PART:"disabler", 0);
+                       }
+               }
+               program { name: "pass_event_disable";
+                       signal: "elm,event,pass,disabled";
+                       source:"elm";
+                       script {
+                               set_mouse_events(PART:"over", 1);
+                               set_mouse_events(PART:"disabler", 1);
+                       }
+               }
+               program { name: "repeat_event_enable";
+                       signal: "elm,event,repeat,enabled";
+                       source: "elm";
+                       script {
+                               set_repeat_events(PART:"over", 1);
+                               set_repeat_events(PART:"disabler", 1);
+                       }
+               }
+               program { name: "repeat_event_disable";
+                       signal: "elm,event,repeat,disabled";
+                       source:"elm";
+                       script {
+                               set_repeat_events(PART:"over", 0);
+                               set_repeat_events(PART:"disabler", 0);
+                       }
+               }
+       }
 }
 
-
 group { name: "elm/spinner/base/settings.datetime";
        parts {
                part { name: "bg";
index 50bf8ff..2a26fd1 100755 (executable)
@@ -308,11 +308,11 @@ static void _set_spinner_button_style(Evas_Object *spinner)
 
 static void _dbg_datetime(Evas_Object *datetime)
 {
-       char *datetime_style = elm_object_style_get(datetime);
+       const char *datetime_style = elm_object_style_get(datetime);
        dlog_print(DLOG_INFO, LOG_TAG, "[%s:%d] DATE_TIME: STYLE: %s", __FILE__, __LINE__, datetime_style);
 
        int i;
-       for (i = 0; i < 20; ++i) {
+       for (i = 0; i < 10; ++i) {
                char buf[255];
                snprintf(buf, 255, "field%d", i);
 
@@ -330,19 +330,18 @@ static void _dbg_datetime(Evas_Object *datetime)
                btn = elm_object_part_content_get(spinner, "elm.swallow.text_button");
                const char *btn_style =   elm_object_style_get(btn);
 
-               dlog_print(DLOG_INFO, LOG_TAG, "[%s:%d] Part(%s) STYLE: %s INC: %s DEC: %s BTN: %s",
+               dlog_print(DLOG_INFO, LOG_TAG, "[%s:%d] {Part(%s) STYLE: %s} INC: %s DEC: %s BTN: %s",
                                __FILE__, __LINE__,
                                buf,
-                               inc_style,
-                               dec_style, btn_style, spinner_style);
+                               spinner_style,
+                               inc_style, dec_style, btn_style);
        }
 }
 
-
 static void _set_spinner_style(Evas_Object *datetime)
 {
        int i;
-       for (i = 0; i < 20; ++i) {
+       for (i = 0; i < 10; ++i) {
                char buf[255];
                snprintf(buf, 255, "field%d", i);
 
@@ -358,6 +357,134 @@ static void _set_spinner_style(Evas_Object *datetime)
        }
 }
 
+static Evas_Object *_get_spinner_button(Evas_Object *datetime, int field)
+{
+       char buf[255];
+       snprintf(buf, 255, "field%d", field);
+
+       Evas_Object *spinner = elm_object_part_content_get(datetime, buf);
+       if (!spinner) {
+               dlog_print(DLOG_ERROR, LOG_TAG, "[%s:%d] part(%s) == NULL", __FILE__, __LINE__, buf);
+               NULL;
+       }
+
+       return elm_object_part_content_get(spinner, "elm.swallow.text_button");
+}
+
+static void _set_obj_focus_dir(Evas_Object *obj, Evas_Object *neighbour, Elm_Focus_Direction dir, bool allow_reverse, Elm_Focus_Direction reverse)
+{
+       elm_object_focus_next_object_set(obj, neighbour, dir);
+
+       if(allow_reverse)
+               elm_object_focus_next_object_set(neighbour, obj, reverse);
+}
+
+static void _set_obj_focus(Evas_Object *obj, Evas_Object *left, Evas_Object *right, Evas_Object *up, Evas_Object *down)
+{
+       _set_obj_focus_dir(obj, up,    ELM_FOCUS_UP,    obj != up,    ELM_FOCUS_DOWN);
+       _set_obj_focus_dir(obj, down,  ELM_FOCUS_DOWN,  obj != down,  ELM_FOCUS_UP);
+       _set_obj_focus_dir(obj, left,  ELM_FOCUS_LEFT,  obj != left,  ELM_FOCUS_RIGHT);
+       _set_obj_focus_dir(obj, right, ELM_FOCUS_RIGHT, obj != right, ELM_FOCUS_LEFT);
+}
+
+static void _set_datetime_focus_chain(Evas_Object *datetime, int start_field, int end_field, Evas_Object *up, Evas_Object *down)
+{
+       Evas_Object *prev = NULL;
+       Evas_Object *btn = NULL;
+
+       btn = _get_spinner_button(datetime, start_field);
+       _set_obj_focus(btn, btn, NULL,
+                       up ? up : btn,
+                       down ? down : btn);
+
+       prev = btn;
+
+       int i;
+       for (i = start_field + 1; i < end_field; ++i) {
+
+               btn = _get_spinner_button(datetime, i);
+               if (!btn) {
+                       dlog_print(DLOG_ERROR, LOG_TAG, "[%s:%d] btn == NULL", __FILE__, __LINE__);
+                       continue;
+               }
+
+               dlog_print(DLOG_DEBUG, LOG_TAG, "[%s:%d] (%d) BUTTON: %s", __FILE__, __LINE__, i, elm_object_text_get(btn));
+
+               _set_obj_focus(btn, prev, NULL,
+                               up ? up : btn,
+                               down ? down : btn);
+
+               prev = btn;
+       }
+
+       btn = _get_spinner_button(datetime, end_field);
+       _set_obj_focus(btn, prev, btn,
+                       up ? up : btn,
+                       down ? down : btn);
+}
+
+static void _dbg_obj_focus(Evas_Object *item, int num)
+{
+       Evas_Object *focus_to;
+       int i;
+       const char *text;
+       const char *type;
+       Elm_Focus_Direction dir;
+       char *dir_names[] = {
+               "ELM_FOCUS_PREVIOUS",
+               "ELM_FOCUS_NEXT",
+               "ELM_FOCUS_UP",
+               "ELM_FOCUS_DOWN",
+               "ELM_FOCUS_RIGHT",
+               "ELM_FOCUS_LEFT",
+       };
+
+       if (!item) {
+               dlog_print(DLOG_ERROR, LOG_TAG, "[%s:%d] item (%d) == NULL", __FILE__, __LINE__, num);
+               return;
+       }
+
+       text = elm_object_text_get(item);
+       type = elm_object_widget_type_get(item);
+
+       dlog_print(DLOG_INFO, LOG_TAG, "[%s:%d] (%d) ITEM: %s TYPE: %s", __FILE__, __LINE__, num, text, type);
+
+       for (dir = ELM_FOCUS_UP; dir < sizeof(dir_names) / sizeof(dir_names[0]); ++dir) {
+               focus_to = elm_object_focus_next_object_get(item, dir);
+               text = elm_object_text_get(focus_to);
+               type = elm_object_widget_type_get(focus_to);
+               dlog_print(DLOG_INFO, LOG_TAG, "[%s:%d] >>>>>>>>>>> %s: %s TYPE: %s", __FILE__, __LINE__, dir_names[dir], text, type);
+       }
+}
+
+static void _dbg_focus_chain(Evas_Object *datetime, int start_field, int end_field)
+{
+       int i = 0;
+       Evas_Object *item;
+
+       for (i = start_field; i <= end_field; ++i) {
+               item = _get_spinner_button(datetime, i);
+               _dbg_obj_focus(item, i);
+       }
+}
+
+static void _set_focus_chain(clock_view_priv_data *priv)
+{
+       Evas_Object *btn_date = _get_spinner_button(priv->date_part, 0);
+       Evas_Object *btn_time = _get_spinner_button(priv->time_part, 0);
+
+       _set_datetime_focus_chain(priv->date_part, 0, 2, NULL, priv->check_24);
+       _set_datetime_focus_chain(priv->time_part, 0, 2, priv->check_24, priv->done);
+
+       _set_obj_focus(priv->check_24, priv->check_24, priv->check_24, btn_date, btn_time);
+       _set_obj_focus(priv->done, priv->done, priv->done, btn_time, priv->done);
+
+       _dbg_focus_chain(priv->date_part, 0, 2);
+       _dbg_obj_focus(priv->check_24, -1);
+       _dbg_focus_chain(priv->time_part, 0, 2);
+       _dbg_obj_focus(priv->done, -1);
+}
+
 static bool _add_clock_setting(clock_view_priv_data *priv)
 {
        SETTING_TRACE_BEGIN
@@ -422,6 +549,7 @@ static bool _add_clock_setting(clock_view_priv_data *priv)
 
        _set_spinner_style(priv->time_part);
        _dbg_datetime(priv->time_part);
+       _set_focus_chain(priv);
 
        inputmgr_add_callback(done, INPUT_HANDLER_TYPE_BTN_DONE, &done_btn_handler, priv);
        inputmgr_add_callback(cancel, INPUT_HANDLER_TYPE_BTN_CANCEL, &cancel_btn_handler, priv);
@@ -550,7 +678,10 @@ static void _show(void *data)
        elm_datetime_value_set(priv->time_part, (Elm_Datetime_Time *)&current_time);
 
        evas_object_show(priv->base);
-       elm_object_focus_set(priv->done, EINA_TRUE);
+
+       Evas_Object *btn = _get_spinner_button(priv->date_part, 0);
+       elm_object_focus_set(btn, EINA_TRUE);
+
        SETTING_TRACE_END;
 }