seoz pushed a commit to branch master. http://git.enlightenment.org/core/elementary.git/commit/?id=74cefaa306861d48df2c7a75b5ebe74d15d68cbb
commit 74cefaa306861d48df2c7a75b5ebe74d15d68cbb Author: nirajkr <[email protected]> Date: Wed Feb 5 19:17:41 2014 +0900 focus: Added elm_object_focus_highlight_style_get/set() to support custom focus highlight on widget Summary: This new API will allow widget to have its own focus highlight style Reviewers: seoz CC: woohyun, singh.amitesh Differential Revision: https://phab.enlightenment.org/D501 --- src/bin/test.c | 4 +++- src/bin/test_focus_style.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++ src/lib/elm_focus.h | 33 +++++++++++++++++++++++++++ src/lib/elm_main.c | 15 ++++++++++++ src/lib/elm_widget.c | 46 ++++++++++++++++++++++++++++++++++++- src/lib/elm_widget.h | 26 +++++++++++++++++++++ src/lib/elm_win.c | 14 ++++++++++-- 7 files changed, 191 insertions(+), 4 deletions(-) diff --git a/src/bin/test.c b/src/bin/test.c index 290cdb7..f3cdfee 100644 --- a/src/bin/test.c +++ b/src/bin/test.c @@ -191,6 +191,7 @@ void test_focus_custom_chain(void *data, Evas_Object *obj, void *event_info); void test_focus_style(void *data, Evas_Object *obj, void *event_info); void test_focus_part(void *data, Evas_Object *obj, void *event_info); void test_focus3(void *data, Evas_Object *obj, void *event_info); +void test_focus_object_style(void *data, Evas_Object *obj, void *event_info); 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); @@ -759,7 +760,8 @@ add_tests: ADD_TEST(NULL, "Focus", "Focus Style", test_focus_style); ADD_TEST(NULL, "Focus", "Focus On Part", test_focus_part); ADD_TEST(NULL, "Focus", "Focus 3", test_focus3); - + ADD_TEST(NULL, "Focus", "Focus Object Style", test_focus_object_style); + //------------------------------// ADD_TEST(NULL, "Naviframe", "Naviframe", test_naviframe); ADD_TEST(NULL, "Naviframe", "Naviframe 2", test_naviframe2); diff --git a/src/bin/test_focus_style.c b/src/bin/test_focus_style.c index a9bfafd..477d256 100644 --- a/src/bin/test_focus_style.c +++ b/src/bin/test_focus_style.c @@ -174,3 +174,60 @@ test_focus_part(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *even evas_object_resize(win, 320, 320); evas_object_show(win); } + +void +test_focus_object_style(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) +{ + Evas_Object *win, *fr, *bx, *bt; + char win_focus_theme[PATH_MAX] = { 0 }; + + snprintf(win_focus_theme, sizeof(win_focus_theme), "%s/objects/test_focus_custom.edj", elm_app_data_dir_get()); + elm_theme_extension_add(NULL, win_focus_theme); + + win = elm_win_util_standard_add("object-focus-style", "Object Focus Style"); + elm_win_autodel_set(win, EINA_TRUE); + elm_win_focus_highlight_enabled_set(win, EINA_TRUE); + elm_win_focus_highlight_animate_set(win, EINA_TRUE); + + fr = elm_frame_add(win); + evas_object_size_hint_weight_set(fr, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_win_resize_object_add(win, fr); + elm_object_style_set(fr, "pad_large"); + evas_object_show(fr); + + bx = elm_box_add(fr); + elm_object_content_set(fr, bx); + evas_object_show(bx); + + bt = elm_button_add(bx); + elm_object_text_set(bt, "Button 1"); + evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_box_pack_end(bx, bt); + evas_object_show(bt); + + bt = elm_button_add(bx); + elm_object_text_set(bt, "Button 2"); + evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_box_pack_end(bx, bt); + evas_object_show(bt); + + bt = elm_button_add(bx); + elm_object_text_set(bt, "Button Glow In Focus Style"); + elm_object_focus_highlight_style_set(bt, "glow"); + evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_box_pack_end(bx, bt); + evas_object_show(bt); + + bt = elm_button_add(bx); + elm_object_text_set(bt, "Button 4"); + evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_box_pack_end(bx, bt); + evas_object_show(bt); + + evas_object_resize(win, 320, 320); + evas_object_show(win); +} diff --git a/src/lib/elm_focus.h b/src/lib/elm_focus.h index 282526a..44c2417 100644 --- a/src/lib/elm_focus.h +++ b/src/lib/elm_focus.h @@ -284,3 +284,36 @@ EAPI void elm_object_tree_focus_allow_set(Evas_Object *obj, Eina * @ingroup Focus */ EAPI Eina_Bool elm_object_tree_focus_allow_get(const Evas_Object *obj); + +/** + * Set the focus highlight style to be used by a given widget. + * + * @param obj The Elementary widget for which focus style needs to be set. + * @param style The name of the focus style to use on it. + * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise. + * + * @note This overrides the style which is set + * by elm_win_focus_highlight_style_set(). + * + * @see elm_object_focus_highlight_style_get + * + * @since 1.9 + * + * @ingroup Focus + */ +EAPI Eina_Bool elm_object_focus_highlight_style_set(Evas_Object *obj, const char *style); + +/** + * Get the focus highlight style to be used by a given widget. + * + * @param obj The Elementary widget to query for its focus highlight style. + * @return The focus highlight style name used by widget. + * + * @see elm_object_focus_highlight_style_set() + * + * @since 1.9 + * + * @ingroup Focus + */ +EAPI const char *elm_object_focus_highlight_style_get(const Evas_Object *obj); + diff --git a/src/lib/elm_main.c b/src/lib/elm_main.c index 883bdc4..90981b0 100644 --- a/src/lib/elm_main.c +++ b/src/lib/elm_main.c @@ -1250,6 +1250,21 @@ elm_object_style_set(Evas_Object *obj, return elm_widget_style_set(obj, style); } +EAPI Eina_Bool +elm_object_focus_highlight_style_set(Evas_Object *obj, + const char *style) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EINA_FALSE); + return elm_widget_focus_highlight_style_set(obj, style); +} + +EAPI const char * +elm_object_focus_highlight_style_get(const Evas_Object *obj) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(obj, NULL); + return elm_widget_focus_highlight_style_get(obj); +} + EAPI const char * elm_object_style_get(const Evas_Object *obj) { diff --git a/src/lib/elm_widget.c b/src/lib/elm_widget.c index 78ec715..1cba17b 100644 --- a/src/lib/elm_widget.c +++ b/src/lib/elm_widget.c @@ -650,6 +650,46 @@ _elm_widget_focus_region_show(Eo *obj, void *_pd EINA_UNUSED, va_list *list EINA } } +EAPI Eina_Bool +elm_widget_focus_highlight_style_set(Evas_Object *obj, const char *style) +{ + ELM_WIDGET_CHECK(obj) EINA_FALSE; + Eina_Bool ret = EINA_FALSE; + eo_do(obj, elm_wdg_focus_highlight_style_set(style, &ret)); + return ret; +} + +static void +_elm_widget_focus_highlight_style_set(Eo *obj EINA_UNUSED, void *_pd, va_list *list) +{ + const char *style = va_arg(*list, const char *); + Eina_Bool *ret = va_arg(*list, Eina_Bool *); + if (ret) *ret = EINA_FALSE; + Elm_Widget_Smart_Data *sd = _pd; + if (eina_stringshare_replace(&sd->focus_highlight_style, style)) + { + if (ret) *ret = EINA_TRUE; + return; + } +} + +EAPI const char * +elm_widget_focus_highlight_style_get(const Evas_Object *obj) +{ + ELM_WIDGET_CHECK(obj) NULL; + const char *ret = NULL; + eo_do((Eo *) obj, elm_wdg_focus_highlight_style_get(&ret)); + return ret; +} + +static void +_elm_widget_focus_highlight_style_get(Eo *obj EINA_UNUSED, void *_pd, va_list *list) +{ + const char **ret = va_arg(*list, const char **); + Elm_Widget_Smart_Data *sd = _pd; + *ret = sd->focus_highlight_style; +} + static void _parent_focus(Evas_Object *obj) { @@ -6424,6 +6464,8 @@ _class_constructor(Eo_Class *klass) EO_OP_FUNC(ELM_WIDGET_ID(ELM_WIDGET_SUB_ID_FOCUS_ORDER_GET), _elm_widget_focus_order_get), EO_OP_FUNC(ELM_WIDGET_ID(ELM_WIDGET_SUB_ID_FOCUS_REGION_GET), _elm_widget_focus_region_get), EO_OP_FUNC(ELM_WIDGET_ID(ELM_WIDGET_SUB_ID_FOCUS_REGION_SHOW), _elm_widget_focus_region_show), + EO_OP_FUNC(ELM_WIDGET_ID(ELM_WIDGET_SUB_ID_FOCUS_HIGHLIGHT_STYLE_SET), _elm_widget_focus_highlight_style_set), + EO_OP_FUNC(ELM_WIDGET_ID(ELM_WIDGET_SUB_ID_FOCUS_HIGHLIGHT_STYLE_GET), _elm_widget_focus_highlight_style_get), EO_OP_FUNC(ELM_WIDGET_ID(ELM_WIDGET_SUB_ID_THEME_OBJECT_SET), _elm_widget_theme_object_set), @@ -6472,7 +6514,7 @@ static const Eo_Op_Description op_desc[] = { EO_OP_DESCRIPTION(ELM_WIDGET_SUB_ID_FOCUS_NEXT, "'Virtual' function handling passing focus to sub-objects."), EO_OP_DESCRIPTION(ELM_WIDGET_SUB_ID_FOCUS_DIRECTION_MANAGER_IS, "'Virtual' function which checks if handling of passing focus to sub-objects in given direction is supported by widget."), EO_OP_DESCRIPTION(ELM_WIDGET_SUB_ID_FOCUS_DIRECTION,"'Virtual' function handling passing focus to sub-objects given a direction, in degrees."), - EO_OP_DESCRIPTION(ELM_WIDGET_SUB_ID_SUB_OBJECT_ADD, "'Virtual' function handling sub objects being added."), + EO_OP_DESCRIPTION(ELM_WIDGET_SUB_ID_SUB_OBJECT_ADD, "'Virtual' function handling sub objects being added."), EO_OP_DESCRIPTION(ELM_WIDGET_SUB_ID_SUB_OBJECT_DEL, "'Virtual' function handling sub objects being removed."), EO_OP_DESCRIPTION(ELM_WIDGET_SUB_ID_ACCESS, "'Virtual' function on the widget being set access."), EO_OP_DESCRIPTION(ELM_WIDGET_SUB_ID_PARENT_SET, "'Virtual' function handling parent widget attachment to new object."), @@ -6572,6 +6614,8 @@ static const Eo_Op_Description op_desc[] = { EO_OP_DESCRIPTION(ELM_WIDGET_SUB_ID_FOCUS_ORDER_GET, "description here"), EO_OP_DESCRIPTION(ELM_WIDGET_SUB_ID_FOCUS_REGION_GET, "Get the focus region of the given widget."), EO_OP_DESCRIPTION(ELM_WIDGET_SUB_ID_FOCUS_REGION_SHOW, "Show the focus region of the given widget."), + EO_OP_DESCRIPTION(ELM_WIDGET_SUB_ID_FOCUS_HIGHLIGHT_STYLE_SET, "Function to set the focus highlight style."), + EO_OP_DESCRIPTION(ELM_WIDGET_SUB_ID_FOCUS_HIGHLIGHT_STYLE_GET, "Function to get the focus highlight style."), EO_OP_DESCRIPTION(ELM_WIDGET_SUB_ID_THEME_OBJECT_SET, "description here"), EO_OP_DESCRIPTION(ELM_WIDGET_SUB_ID_ORIENTATION_SET, "description here"), diff --git a/src/lib/elm_widget.h b/src/lib/elm_widget.h index 834d68e..a040ff2 100644 --- a/src/lib/elm_widget.h +++ b/src/lib/elm_widget.h @@ -395,6 +395,7 @@ typedef struct _Elm_Widget_Smart_Data double scale; Elm_Theme *theme; const char *style; + const char *focus_highlight_style; /**< custom focus style for a widget */ const char *access_info; unsigned int focus_order; Eina_Bool focus_order_on_calc; @@ -643,6 +644,8 @@ EAPI Eina_Bool elm_widget_focus_list_direction_get(const Evas_Object *ob EAPI Eina_Bool elm_widget_focus_list_next_get(const Evas_Object *obj, const Eina_List *items, void *(*list_data_get)(const Eina_List *list), Elm_Focus_Direction dir, Evas_Object **next); EAPI Evas_Object *elm_widget_focus_next_object_get(const Evas_Object *obj, Elm_Focus_Direction dir); EAPI void elm_widget_focus_next_object_set(Evas_Object *obj, Evas_Object *next, Elm_Focus_Direction dir); +EAPI Eina_Bool elm_widget_focus_highlight_style_set(Evas_Object *obj, const char *style); +EAPI const char *elm_widget_focus_highlight_style_get(const Evas_Object *obj); EAPI void elm_widget_parent_highlight_set(Evas_Object *obj, Eina_Bool highlighted); EAPI void elm_widget_focus_set(Evas_Object *obj, Eina_Bool focus); EAPI void elm_widget_focused_object_clear(Evas_Object *obj); @@ -1216,6 +1219,8 @@ enum ELM_WIDGET_SUB_ID_FOCUS_ORDER_GET, ELM_WIDGET_SUB_ID_FOCUS_REGION_GET, ELM_WIDGET_SUB_ID_FOCUS_REGION_SHOW, + ELM_WIDGET_SUB_ID_FOCUS_HIGHLIGHT_STYLE_SET, + ELM_WIDGET_SUB_ID_FOCUS_HIGHLIGHT_STYLE_GET, ELM_WIDGET_SUB_ID_THEME_OBJECT_SET, ELM_WIDGET_SUB_ID_ORIENTATION_SET, @@ -2318,6 +2323,27 @@ typedef void * (*list_data_get_func_type)(const Eina_List * l); #define elm_wdg_focus_region_show() ELM_WIDGET_ID(ELM_WIDGET_SUB_ID_FOCUS_REGION_SHOW) /** + * @def elm_wdg_focus_highlight_style_set + * @since 1.9 + * + * This function set the widget focus highlight style. + * + * @param[in] style + * @param[out] ret + */ +#define elm_wdg_focus_highlight_style_set(style, ret) ELM_WIDGET_ID(ELM_WIDGET_SUB_ID_FOCUS_HIGHLIGHT_STYLE_SET), EO_TYPECHECK(const char *, style), EO_TYPECHECK(Eina_Bool *, ret) + +/** + * @def elm_wdg_focus_highlight_style_get + * @since 1.9 + * + * This function returns the widget focus highlight style. + * + * @param[out] ret + */ +#define elm_wdg_focus_highlight_style_get(ret) ELM_WIDGET_ID(ELM_WIDGET_SUB_ID_FOCUS_HIGHLIGHT_STYLE_GET), EO_TYPECHECK(const char **, ret) + +/** * @def elm_wdg_theme_object_set * @since 1.8 * diff --git a/src/lib/elm_win.c b/src/lib/elm_win.c index b878ba8..de10924 100644 --- a/src/lib/elm_win.c +++ b/src/lib/elm_win.c @@ -767,6 +767,8 @@ _elm_win_focus_highlight_reconfigure(Elm_Win_Smart_Data *sd) Eina_Bool visible_changed; Eina_Bool common_visible; const char *sig = NULL; + const char *focus_style_target = NULL; + const char *focus_style_previous = NULL; _elm_win_focus_highlight_reconfigure_job_stop(sd); @@ -801,13 +803,21 @@ _elm_win_focus_highlight_reconfigure(Elm_Win_Smart_Data *sd) if ((!target) || (!common_visible) || (sd->focus_highlight.cur.in_theme)) goto the_end; - if (sd->focus_highlight.theme_changed) + focus_style_previous = elm_widget_focus_highlight_style_get(previous); + focus_style_target = elm_widget_focus_highlight_style_get(target); + + if (sd->focus_highlight.theme_changed || + (focus_style_target != focus_style_previous)) { const char *str; - if (sd->focus_highlight.style) + + if (focus_style_target) + str = focus_style_target; + else if (sd->focus_highlight.style) str = sd->focus_highlight.style; else str = "default"; + elm_widget_theme_object_set (sd->obj, fobj, "focus_highlight", "top", str); sd->focus_highlight.theme_changed = EINA_FALSE; --
