diff options
author | Bora Hwang <bora1.hwang@samsung.com> | 2014-02-09 18:11:47 +0900 |
---|---|---|
committer | Daniel Juyung Seo <seojuyung2@gmail.com> | 2014-02-09 18:11:47 +0900 |
commit | f086ac9a971198d9991edee43d3c5db50a0db9da (patch) | |
tree | 6eff8c178138cc98d16c6e866b061fdb30d18009 | |
parent | 625e63399da158d64ccf51a7e73a1ecb1dfd14f7 (diff) | |
download | elementary-f086ac9a971198d9991edee43d3c5db50a0db9da.tar.gz |
ctxpopup: add a new api for ctxpopup which makes ctxpopup not to hide automatically
Summary:
Developer can use this API for the case when he/she wants ctxpopup not to hide
automatically when parent of ctxpopup is resized or language is changed.
Default value of "disabled" is EINA_FALSE. So if user sets "disabled" EINA_TRUE
and parent size changes, ctxpopup recalculates its size and position.
Since size of bg is set when setting parent only, it should be resized again.
Reviewers: Hermet, seoz, thiepha, raster
CC: c
Differential Revision: https://phab.enlightenment.org/D510
-rw-r--r-- | src/bin/test_ctxpopup.c | 29 | ||||
-rw-r--r-- | src/lib/elc_ctxpopup.c | 63 | ||||
-rw-r--r-- | src/lib/elc_ctxpopup_eo.h | 30 | ||||
-rw-r--r-- | src/lib/elc_ctxpopup_legacy.h | 34 | ||||
-rw-r--r-- | src/lib/elm_widget_ctxpopup.h | 1 |
5 files changed, 152 insertions, 5 deletions
diff --git a/src/bin/test_ctxpopup.c b/src/bin/test_ctxpopup.c index 99f961eb7..4f807f6a7 100644 --- a/src/bin/test_ctxpopup.c +++ b/src/bin/test_ctxpopup.c @@ -35,6 +35,7 @@ _print_current_dir(Evas_Object *obj) printf("ctxpopup direction: unknow!\n"); break; } + printf(" [%s : %d] auto_hide_mode=%d\n", __func__, __LINE__, elm_ctxpopup_auto_hide_disabled_get(obj)); } static void @@ -324,6 +325,32 @@ _list_item_cb7(void *data EINA_UNUSED, Evas_Object *obj, void *event_info EINA_U } static void +_list_item_cb8(void *data EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED) +{ + Evas_Object *ctxpopup; + Elm_Object_Item *it = NULL; + Evas_Coord x,y; + + if (list_mouse_down > 0) return; + + ctxpopup = elm_ctxpopup_add(obj); + evas_object_smart_callback_add(ctxpopup, "dismissed", _dismissed, NULL); + elm_ctxpopup_auto_hide_disabled_set(ctxpopup, EINA_TRUE); + + _ctxpopup_item_new(ctxpopup, "Go to home folder", "home"); + _ctxpopup_item_new(ctxpopup, "Save file", "file"); + _ctxpopup_item_new(ctxpopup, "Delete file", "delete"); + it = _ctxpopup_item_new(ctxpopup, "Navigate to folder", "folder"); + elm_object_item_disabled_set(it, EINA_TRUE); + _ctxpopup_item_new(ctxpopup, "Edit entry", "edit"); + + evas_pointer_canvas_xy_get(evas_object_evas_get(obj), &x, &y); + evas_object_move(ctxpopup, x, y); + evas_object_show(ctxpopup); + _print_current_dir(ctxpopup); +} + +static void _list_clicked(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info) { elm_list_item_selected_set(event_info, EINA_FALSE); @@ -380,6 +407,8 @@ test_ctxpopup(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_ _list_item_cb6, NULL); elm_list_item_append(list, "Ctxpopup with callback function", NULL, NULL, _list_item_cb7, NULL); + elm_list_item_append(list, "Ctxpopup with auto hide disabled mode", NULL, NULL, + _list_item_cb8, NULL); evas_object_show(list); elm_list_go(list); diff --git a/src/lib/elc_ctxpopup.c b/src/lib/elc_ctxpopup.c index eb691c8d3..891fa490b 100644 --- a/src/lib/elc_ctxpopup.c +++ b/src/lib/elc_ctxpopup.c @@ -39,7 +39,7 @@ _elm_ctxpopup_smart_translate(Eo *obj, void *_pd, va_list *list) Eina_List *l; Elm_Ctxpopup_Item *it; - evas_object_hide(obj); + if (sd->auto_hide) evas_object_hide(obj); EINA_LIST_FOREACH(sd->items, l, it) elm_widget_item_translate(it); @@ -634,7 +634,7 @@ static void _elm_ctxpopup_smart_sizing_eval(Eo *obj, void *_pd, va_list *list EINA_UNUSED) { Evas_Coord_Rectangle rect = { 0, 0, 1, 1 }; - Evas_Coord_Point list_size = { 0, 0 }; + Evas_Coord_Point list_size = { 0, 0 }, parent_size = {0, 0}; Elm_Ctxpopup_Smart_Data *sd = _pd; ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd); @@ -660,6 +660,9 @@ _elm_ctxpopup_smart_sizing_eval(Eo *obj, void *_pd, va_list *list EINA_UNUSED) } } + evas_object_geometry_get(sd->parent, NULL, NULL, &parent_size.x, &parent_size.y); + evas_object_resize(sd->bg, parent_size.x, parent_size.y); + evas_object_move(wd->resize_obj, rect.x, rect.y); evas_object_resize(wd->resize_obj, rect.w, rect.h); @@ -696,10 +699,18 @@ _on_parent_resize(void *data, { ELM_CTXPOPUP_DATA_GET(data, sd); - sd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN; + if (sd->auto_hide) + { + sd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN; - evas_object_hide(data); - evas_object_smart_callback_call(data, SIG_DISMISSED, NULL); + evas_object_hide(data); + evas_object_smart_callback_call(data, SIG_DISMISSED, NULL); + } + else + { + if (sd->visible) + elm_layout_sizing_eval(data); + } } static void @@ -1128,6 +1139,7 @@ _elm_ctxpopup_smart_add(Eo *obj, void *_pd, va_list *list EINA_UNUSED) priv->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT; priv->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN; priv->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN; + priv->auto_hide = EINA_TRUE; priv->box = elm_box_add(obj); evas_object_size_hint_weight_set @@ -1478,6 +1490,43 @@ _dismiss(Eo *obj, void *_pd, va_list *list EINA_UNUSED) _hide_signals_emit(obj, sd->dir); } +EAPI void +elm_ctxpopup_auto_hide_disabled_set(Evas_Object *obj, Eina_Bool disabled) +{ + ELM_CTXPOPUP_CHECK(obj); + eo_do(obj, elm_obj_ctxpopup_auto_hide_disabled_set(disabled)); +} + +static void +_auto_hide_disabled_set(Eo *obj EINA_UNUSED, void *_pd, va_list *list) +{ + Eina_Bool disabled = va_arg(*list, int); + + Elm_Ctxpopup_Smart_Data *sd = _pd; + + disabled = !!disabled; + if (sd->auto_hide == !disabled) return; + sd->auto_hide = !disabled; +} + +EAPI Eina_Bool +elm_ctxpopup_auto_hide_disabled_get(const Evas_Object *obj) +{ + ELM_CTXPOPUP_CHECK(obj) EINA_FALSE; + Eina_Bool ret = EINA_FALSE; + eo_do((Eo *) obj, elm_obj_ctxpopup_auto_hide_disabled_get(&ret)); + return ret; +} + +static void +_auto_hide_disabled_get(Eo *obj EINA_UNUSED, void *_pd, va_list *list) +{ + Eina_Bool *ret = va_arg(*list, Eina_Bool *); + Elm_Ctxpopup_Smart_Data *sd = _pd; + + if (ret) *ret = sd->auto_hide; +} + static void _class_constructor(Eo_Class *klass) { @@ -1515,6 +1564,8 @@ _class_constructor(Eo_Class *klass) EO_OP_FUNC(ELM_OBJ_CTXPOPUP_ID(ELM_OBJ_CTXPOPUP_SUB_ID_DIRECTION_PRIORITY_GET), _direction_priority_get), EO_OP_FUNC(ELM_OBJ_CTXPOPUP_ID(ELM_OBJ_CTXPOPUP_SUB_ID_DIRECTION_GET), _direction_get), EO_OP_FUNC(ELM_OBJ_CTXPOPUP_ID(ELM_OBJ_CTXPOPUP_SUB_ID_DISMISS), _dismiss), + EO_OP_FUNC(ELM_OBJ_CTXPOPUP_ID(ELM_OBJ_CTXPOPUP_SUB_ID_AUTO_HIDE_DISABLED_SET), _auto_hide_disabled_set), + EO_OP_FUNC(ELM_OBJ_CTXPOPUP_ID(ELM_OBJ_CTXPOPUP_SUB_ID_AUTO_HIDE_DISABLED_GET), _auto_hide_disabled_get), EO_OP_FUNC_SENTINEL }; eo_class_funcs_set(klass, func_desc); @@ -1532,6 +1583,8 @@ static const Eo_Op_Description op_desc[] = { EO_OP_DESCRIPTION(ELM_OBJ_CTXPOPUP_SUB_ID_DIRECTION_PRIORITY_GET, "Get the direction priority of a ctxpopup."), EO_OP_DESCRIPTION(ELM_OBJ_CTXPOPUP_SUB_ID_DIRECTION_GET, "Get the current direction of a ctxpopup."), EO_OP_DESCRIPTION(ELM_OBJ_CTXPOPUP_SUB_ID_DISMISS, "Dismiss a ctxpopup object."), + EO_OP_DESCRIPTION(ELM_OBJ_CTXPOPUP_SUB_ID_AUTO_HIDE_DISABLED_SET, "Set ctxpopup auto hide mode triggered by ctxpopup policy"), + EO_OP_DESCRIPTION(ELM_OBJ_CTXPOPUP_SUB_ID_AUTO_HIDE_DISABLED_GET, "Get ctxpopup auto hide mode triggered by ctxpopup policy"), EO_OP_DESCRIPTION_SENTINEL }; static const Eo_Class_Description class_desc = { diff --git a/src/lib/elc_ctxpopup_eo.h b/src/lib/elc_ctxpopup_eo.h index a26d1919f..2bb93f40e 100644 --- a/src/lib/elc_ctxpopup_eo.h +++ b/src/lib/elc_ctxpopup_eo.h @@ -16,6 +16,8 @@ enum ELM_OBJ_CTXPOPUP_SUB_ID_DIRECTION_PRIORITY_GET, ELM_OBJ_CTXPOPUP_SUB_ID_DIRECTION_GET, ELM_OBJ_CTXPOPUP_SUB_ID_DISMISS, + ELM_OBJ_CTXPOPUP_SUB_ID_AUTO_HIDE_DISABLED_SET, + ELM_OBJ_CTXPOPUP_SUB_ID_AUTO_HIDE_DISABLED_GET, ELM_OBJ_CTXPOPUP_SUB_ID_LAST }; @@ -169,3 +171,31 @@ enum * @ingroup Ctxpopup */ #define elm_obj_ctxpopup_dismiss() ELM_OBJ_CTXPOPUP_ID(ELM_OBJ_CTXPOPUP_SUB_ID_DISMISS) + +/** + * @def elm_obj_ctxpopup_auto_hide_disabled_set + * @since 1.9 + * + * @brief Set whether ctxpopup hide automatically or not by ctxpopup policy + * + * @param[in] disabled + * + * @see elm_ctxpopup_auto_hide_disabled_get + * + * @ingroup Ctxpopup + */ +#define elm_obj_ctxpopup_auto_hide_disabled_set(disabled) ELM_OBJ_CTXPOPUP_ID(ELM_OBJ_CTXPOPUP_SUB_ID_AUTO_HIDE_DISABLED_SET), EO_TYPECHECK(Eina_Bool, disabled) + +/** + * @def elm_obj_ctxpopup_auto_hide_disabled_get + * @since 1.9 + * + * @brief Get whether ctxpopup hide automatically or not by ctxpopup policy + * + * @param[out] ret + * + * @see elm_ctxpopup_auto_hide_disabled_set + * + * @ingroup Ctxpopup + */ +#define elm_obj_ctxpopup_auto_hide_disabled_get(ret) ELM_OBJ_CTXPOPUP_ID(ELM_OBJ_CTXPOPUP_SUB_ID_AUTO_HIDE_DISABLED_GET), EO_TYPECHECK(Eina_Bool *, ret)
\ No newline at end of file diff --git a/src/lib/elc_ctxpopup_legacy.h b/src/lib/elc_ctxpopup_legacy.h index 754182cbc..91aad2397 100644 --- a/src/lib/elc_ctxpopup_legacy.h +++ b/src/lib/elc_ctxpopup_legacy.h @@ -142,3 +142,37 @@ EAPI Elm_Ctxpopup_Direction elm_ctxpopup_direction_get(const Evas_Object * * emitted. */ EAPI void elm_ctxpopup_dismiss(Evas_Object *obj); + +/** + * @brief Set ctxpopup auto hide mode triggered by ctxpopup policy. + * @since 1.9 + * + * @param obj The ctxpopup object + * @param disabled auto hide enable/disable. + * + * Use this function when user wants ctxpopup not to hide automatically. + * By default, ctxpopup is dismissed whenever mouse clicked its background area, language is changed, + * and its parent geometry is updated(changed). + * Not to hide ctxpopup automatically, disable auto hide function by calling this API, + * then ctxpopup won't be dismissed in those scenarios. + * + * Default value of disabled is @c EINA_FALSE. + * + * @see elm_ctxpopup_auto_hide_disabled_get() + * + * @ingroup Ctxpopup + */ +EAPI void elm_ctxpopup_auto_hide_disabled_set(Evas_Object *obj, Eina_Bool disabled); + +/** + * @brief Get ctxpopup auto hide mode triggered by ctxpopup policy. + * @since 1.9 + * + * @param obj The ctxpopup object + * @return auto hide mode's state of a ctxpopup + * + * @see elm_ctxpopup_auto_hide_disabled_set() for more information. + * + * @ingroup Ctxpopup + */ +EAPI Eina_Bool elm_ctxpopup_auto_hide_disabled_get(const Evas_Object *obj); diff --git a/src/lib/elm_widget_ctxpopup.h b/src/lib/elm_widget_ctxpopup.h index ab681226c..cd10ffec5 100644 --- a/src/lib/elm_widget_ctxpopup.h +++ b/src/lib/elm_widget_ctxpopup.h @@ -53,6 +53,7 @@ struct _Elm_Ctxpopup_Smart_Data Eina_Bool finished : 1; Eina_Bool emitted : 1; Eina_Bool visible : 1; + Eina_Bool auto_hide : 1; /**< auto hide mode triggered by ctxpopup policy*/ }; /** |