elm_focus: implement elm_object_focus_next_item_set / get
authorMarcel Hollerbach <mail@marcel-hollerbach.de>
Mon, 3 Dec 2018 10:46:48 +0000 (11:46 +0100)
committerWonki Kim <wonki_.kim@samsung.com>
Tue, 18 Dec 2018 04:44:53 +0000 (13:44 +0900)
you can use this now to let the focus move to the widget container of
the passed item.

I know this patch contains a whitespace change, but i have to get out
this whitespace each & every time i am editing the file - which is
annoying. So remove it once, which makes further work easier.

fixes T6183.

Reviewed-by: YeongJong Lee <yj34.lee@samsung.com>
Differential Revision: https://phab.enlightenment.org/D7408

src/bin/elementary/test.c
src/bin/elementary/test_focus.c
src/lib/elementary/elm_focus_legacy.c

index 1cedec2..9298e9b 100644 (file)
@@ -258,6 +258,7 @@ void test_focus_object_policy(void *data, Evas_Object *obj, void *event_info);
 void test_focus4(void *data, Evas_Object *obj, void *event_info);
 void test_focus5(void *data, Evas_Object *obj, void *event_info);
 void test_focus6(void *data, Evas_Object *obj, void *event_info);
+void test_focus7(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED);
 void test_flipselector(void *data, Evas_Object *obj, void *event_info);
 void test_diskselector(void *data, Evas_Object *obj, void *event_info);
 void test_colorselector(void *data, Evas_Object *obj, void *event_info);
@@ -1147,6 +1148,7 @@ add_tests:
    ADD_TEST(NULL, "Focus", "Focus 4", test_focus4);
    ADD_TEST(NULL, "Focus", "Focus 5", test_focus5);
    ADD_TEST(NULL, "Focus", "Focus 6", test_focus6);
+   ADD_TEST(NULL, "Focus", "Focus 7", test_focus7);
 
    //------------------------------//
    ADD_TEST(NULL, "Naviframe", "Naviframe", test_naviframe);
index ceb6e5c..d1b04ee 100644 (file)
@@ -1031,7 +1031,7 @@ _focus5_btn_clicked(void *data, Evas_Object *obj EINA_UNUSED, void *event_info E
    Evas_Object *grid = data;
    struct _focus5_obj *layout = evas_object_data_get(grid, "layout");
 
-   // brrr...a really naive looping 
+   // brrr...a really naive looping
    if (layout == _focus5_layout_data1)
       _focus5_layout(grid, _focus5_layout_data2);
    else if (layout == _focus5_layout_data2)
@@ -1224,3 +1224,63 @@ test_focus6(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_in
    evas_object_resize(win, 400, 400);
    evas_object_show(win);
 }
+
+void
+test_focus7(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
+{
+   Evas_Object *win, *box, *btn, *gl;
+   Elm_Genlist_Item_Class *itc;
+   Elm_Object_Item *it;
+   int i;
+
+   win = elm_win_util_standard_add("focus7", "Focus 7");
+   elm_win_autodel_set(win, EINA_TRUE);
+   elm_win_focus_highlight_enabled_set(win, EINA_TRUE);
+
+   // main vertical box
+   box = elm_box_add(win);
+   evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+   elm_win_resize_object_add(win, box);
+   evas_object_show(box);
+
+   // genlist in a swallow
+   gl = elm_genlist_add(box);
+   evas_object_size_hint_weight_set(gl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+   evas_object_size_hint_align_set(gl, EVAS_HINT_FILL, EVAS_HINT_FILL);
+   elm_genlist_select_mode_set(gl, ELM_OBJECT_SELECT_MODE_ALWAYS);
+   elm_box_pack_end(box, gl);
+
+   itc = elm_genlist_item_class_new();
+   itc->item_style = "default";
+   itc->func.text_get = _focus6_gl_text_get;
+   for (i = 0; i < 3; i++)
+     {
+        it = elm_genlist_item_append(gl, itc, (void*)(uintptr_t)i, NULL,
+                                     ELM_GENLIST_ITEM_NONE, NULL, NULL);
+
+        if (i == 1)
+          {
+             elm_genlist_item_selected_set(it, EINA_TRUE);
+
+             /* focus should start from second item */
+             elm_object_item_focus_set(it, EINA_TRUE);
+          }
+     }
+   elm_genlist_item_class_free(itc);
+   evas_object_show(gl);
+
+   btn = elm_button_add(win);
+   elm_object_text_set(btn, "To the right will result in genlist focus");
+   elm_object_focus_next_item_set(btn, it, ELM_FOCUS_RIGHT);
+   elm_box_pack_end(box, btn);
+   evas_object_show(btn);
+
+   btn = elm_button_add(win);
+   elm_object_text_set(btn, "UP");
+   elm_box_pack_end(box, btn);
+   evas_object_show(btn);
+
+   // size and show the window
+   evas_object_resize(win, 400, 400);
+   evas_object_show(win);
+}
index 3490fc7..7f87cbd 100644 (file)
@@ -215,10 +215,18 @@ elm_object_focus_next(Evas_Object        *obj,
         Efl_Ui_Focus_Object *legacy_target = NULL;
         ELM_WIDGET_DATA_GET_OR_RETURN(logical, pd_logical);
 
-        #define MAP(direction, field)  if (dir == EFL_UI_FOCUS_DIRECTION_ ##direction && pd_logical->legacy_focus.field) legacy_target = pd_logical->legacy_focus.field;
+
+        #define MAP(direction, field)  if (dir == EFL_UI_FOCUS_DIRECTION_ ##direction && pd_logical->legacy_focus.item_ ##field) legacy_target = elm_object_item_widget_get(pd_logical->legacy_focus.item_ ##field);
         MAPPING()
         #undef MAP
 
+        if (!legacy_target)
+          {
+             #define MAP(direction, field)  if (dir == EFL_UI_FOCUS_DIRECTION_ ##direction && pd_logical->legacy_focus.field) legacy_target = pd_logical->legacy_focus.field;
+             MAPPING()
+             #undef MAP
+          }
+
         if (legacy_target)
           {
              efl_ui_focus_util_focus(EFL_UI_FOCUS_UTIL_CLASS, legacy_target);
@@ -270,9 +278,14 @@ elm_object_focus_next_item_get(const Evas_Object  *obj,
                                Elm_Focus_Direction dir EINA_UNUSED)
 {
    API_ENTRY_VAL(NULL)
-   /* FOCUS-FIXME */
-   //TIZEN_ONLY(20180607): Restore legacy focus
-   //return NULL;
+
+   /* TIZEN_ONLY(20180607): Restore legacy focus
+    #define MAP(direction, field)  if (dir == EFL_UI_FOCUS_DIRECTION_ ##direction && pd->legacy_focus.item_ ##field) return pd->legacy_focus.item_ ##field;
+   MAPPING()
+   #undef MAP
+
+   return NULL;
+   */
    return efl_ui_widget_focus_next_item_get(obj, dir);
    //
 }
@@ -283,8 +296,12 @@ elm_object_focus_next_item_set(Evas_Object     *obj,
                                Elm_Focus_Direction dir EINA_UNUSED)
 {
    API_ENTRY()
-   /* FOCUS-FIXME */
-   //TIZEN_ONLY(20180607): Restore legacy focus
+
+   /* TIZEN_ONLY(20180607): Restore legacy focus
+   #define MAP(direction, field)  if (dir == EFL_UI_FOCUS_DIRECTION_ ##direction) pd->legacy_focus.item_ ##field = next_item;
+   MAPPING()
+   #undef MAP
+   */
    efl_ui_widget_focus_next_item_set(obj, next_item, dir);
    //
 }