entry: Add elm_entry_select_region_set API

Summary:
in case of GTK, it provides API to select a region of text (gtk_editable_select_region).
However, there are only API to select all or none in EFL.
This API will provide the way to select a region of text.

Test Plan: elementary_test > entry3 > press 'Region' button

Reviewers: woohyun, tasn, id213sin

Reviewed By: tasn

Differential Revision: https://phab.enlightenment.org/D520
devs/felipealmeida/promises
Jihoon Kim 9 years ago committed by Tom Hacohen
parent 23f20bb23d
commit ac16bd6fe6
  1. 17
      legacy/elementary/src/bin/test_entry.c
  2. 32
      legacy/elementary/src/lib/elm_entry.c
  3. 16
      legacy/elementary/src/lib/elm_entry_eo.h
  4. 11
      legacy/elementary/src/lib/elm_entry_legacy.h

@ -657,6 +657,13 @@ my_ent_bt_non(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UN
elm_entry_select_none(en);
}
static void
my_ent_bt_region(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
Evas_Object *en = data;
elm_entry_select_region_set(en, 10, 16);
}
static void
my_ent_bt_ins(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
@ -934,6 +941,16 @@ test_entry3(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_in
elm_object_focus_allow_set(bt, EINA_FALSE);
evas_object_show(bt);
bt = elm_button_add(win);
elm_object_text_set(bt, "Region");
evas_object_smart_callback_add(bt, "clicked", my_ent_bt_region, en);
evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0.0);
elm_box_pack_end(bx2, bt);
evas_object_propagate_events_set(bt, EINA_FALSE);
elm_object_focus_allow_set(bt, EINA_FALSE);
evas_object_show(bt);
bt = elm_button_add(win);
elm_object_text_set(bt, "Ins");
evas_object_smart_callback_add(bt, "clicked", my_ent_bt_ins, en);

@ -4018,6 +4018,36 @@ _select_all(Eo *obj EINA_UNUSED, void *_pd, va_list *list EINA_UNUSED)
edje_object_part_text_select_all(sd->entry_edje, "elm.text");
}
EAPI void
elm_entry_select_region_set(Evas_Object *obj, int start, int end)
{
ELM_ENTRY_CHECK(obj);
eo_do(obj, elm_obj_entry_select_region_set(start, end));
}
static void
_select_region_set(Eo *obj EINA_UNUSED, void *_pd, va_list *list)
{
Elm_Entry_Smart_Data *sd = _pd;
int start = va_arg(*list, int);
int end = va_arg(*list, int);
if ((sd->password)) return;
if (sd->sel_mode)
{
sd->sel_mode = EINA_FALSE;
if (!_elm_config->desktop_entry)
edje_object_part_text_select_allow_set
(sd->entry_edje, "elm.text", EINA_FALSE);
edje_object_signal_emit(sd->entry_edje, "elm,state,select,off", "elm");
}
edje_object_part_text_cursor_pos_set(sd->entry_edje, "elm.text", EDJE_CURSOR_MAIN, start);
edje_object_part_text_select_begin(sd->entry_edje, "elm.text");
edje_object_part_text_cursor_pos_set(sd->entry_edje, "elm.text", EDJE_CURSOR_MAIN, end);
edje_object_part_text_select_extend(sd->entry_edje, "elm.text");
}
EAPI Eina_Bool
elm_entry_cursor_geometry_get(const Evas_Object *obj,
Evas_Coord *x,
@ -5880,6 +5910,7 @@ _class_constructor(Eo_Class *klass)
EO_OP_FUNC(ELM_OBJ_ENTRY_ID(ELM_OBJ_ENTRY_SUB_ID_EDITABLE_GET), _editable_get),
EO_OP_FUNC(ELM_OBJ_ENTRY_ID(ELM_OBJ_ENTRY_SUB_ID_SELECT_NONE), _select_none),
EO_OP_FUNC(ELM_OBJ_ENTRY_ID(ELM_OBJ_ENTRY_SUB_ID_SELECT_ALL), _select_all),
EO_OP_FUNC(ELM_OBJ_ENTRY_ID(ELM_OBJ_ENTRY_SUB_ID_SELECT_REGION_SET), _select_region_set),
EO_OP_FUNC(ELM_OBJ_ENTRY_ID(ELM_OBJ_ENTRY_SUB_ID_CURSOR_GEOMETRY_GET), _cursor_geometry_get),
EO_OP_FUNC(ELM_OBJ_ENTRY_ID(ELM_OBJ_ENTRY_SUB_ID_CURSOR_NEXT), _cursor_next),
EO_OP_FUNC(ELM_OBJ_ENTRY_ID(ELM_OBJ_ENTRY_SUB_ID_CURSOR_PREV), _cursor_prev),
@ -5979,6 +6010,7 @@ static const Eo_Op_Description op_desc[] = {
EO_OP_DESCRIPTION(ELM_OBJ_ENTRY_SUB_ID_EDITABLE_GET, "Get whether the entry is editable or not."),
EO_OP_DESCRIPTION(ELM_OBJ_ENTRY_SUB_ID_SELECT_NONE, "This drops any existing text selection within the entry."),
EO_OP_DESCRIPTION(ELM_OBJ_ENTRY_SUB_ID_SELECT_ALL, "This selects all text within the entry."),
EO_OP_DESCRIPTION(ELM_OBJ_ENTRY_SUB_ID_SELECT_REGION_SET, "This selects a region of text within the entry."),
EO_OP_DESCRIPTION(ELM_OBJ_ENTRY_SUB_ID_CURSOR_GEOMETRY_GET, "This function returns the geometry of the cursor."),
EO_OP_DESCRIPTION(ELM_OBJ_ENTRY_SUB_ID_CURSOR_NEXT, "This moves the cursor one place to the right within the entry."),
EO_OP_DESCRIPTION(ELM_OBJ_ENTRY_SUB_ID_CURSOR_PREV, "This moves the cursor one place to the left within the entry."),

@ -27,6 +27,7 @@ enum
ELM_OBJ_ENTRY_SUB_ID_EDITABLE_GET,
ELM_OBJ_ENTRY_SUB_ID_SELECT_NONE,
ELM_OBJ_ENTRY_SUB_ID_SELECT_ALL,
ELM_OBJ_ENTRY_SUB_ID_SELECT_REGION_SET,
ELM_OBJ_ENTRY_SUB_ID_CURSOR_GEOMETRY_GET,
ELM_OBJ_ENTRY_SUB_ID_CURSOR_NEXT,
ELM_OBJ_ENTRY_SUB_ID_CURSOR_PREV,
@ -394,6 +395,21 @@ enum
*/
#define elm_obj_entry_select_all() ELM_OBJ_ENTRY_ID(ELM_OBJ_ENTRY_SUB_ID_SELECT_ALL)
/**
* @def elm_obj_entry_select_region_set
* @since 1.9
*
* This selects a region of text within the entry.
*
* @param[in] start
* @param[in] end
*
* @see elm_entry_select_region_set
*
* @ingroup Entry
*/
#define elm_obj_entry_select_region_set(start, end) ELM_OBJ_ENTRY_ID(ELM_OBJ_ENTRY_SUB_ID_SELECT_REGION_SET), EO_TYPECHECK(int, start), EO_TYPECHECK(int, end)
/**
* @def elm_obj_entry_cursor_geometry_get
* @since 1.8

@ -347,6 +347,17 @@ EAPI void elm_entry_select_none(Evas_Object *obj);
*/
EAPI void elm_entry_select_all(Evas_Object *obj);
/**
* This selects a region of text within the entry.
*
* @param obj The entry object
* @param start The starting position
* @param end The end position
*
* @ingroup Entry
*/
EAPI void elm_entry_select_region_set(Evas_Object *obj, int start, int end);
/**
* This function returns the geometry of the cursor.
*

Loading…
Cancel
Save