END_TEST START_TEST (elm_entry_atspi_text_selections) { Evas_Object *win, *entry; int val, start, end; const char *str; Eina_Bool ret; const char *txt = "Lorem ipśum<br> dolor sit\n amęt"; elm_init(1, NULL); win = elm_win_add(NULL, "entry", ELM_WIN_BASIC); entry = elm_entry_add(win); elm_object_text_set(entry, txt); eo_do(entry, val = elm_interface_atspi_text_selections_count_get()); ck_assert(val == 0); elm_entry_select_region_set(entry, 2, 4); eo_do(entry, val = elm_interface_atspi_text_selections_count_get()); ck_assert(val == 1); eo_do(entry, elm_interface_atspi_text_selection_get(0, &start, &end)); ck_assert(start == 2); ck_assert(end == 4); elm_entry_select_region_set(entry, 6, 10); eo_do(entry, val = elm_interface_atspi_text_selections_count_get()); ck_assert(val == 1); eo_do(entry, elm_interface_atspi_text_selection_get(0, &start, &end)); ck_assert(start == 6); ck_assert(end == 10); elm_entry_select_none(entry); eo_do(entry, ret = elm_interface_atspi_text_selection_add(2, 5)); ck_assert(ret == EINA_TRUE); str = elm_entry_selection_get(entry); ck_assert_str_eq(str, "rem"); eo_do(entry, ret = elm_interface_atspi_text_selection_remove(0)); ck_assert(ret == EINA_TRUE); str = elm_entry_selection_get(entry); ck_assert(str == NULL); elm_shutdown(); }
static Eina_Bool _find_in_entry(Evas_Object *entry, const char *text, Eina_Bool jump_next) { Eina_Bool try_next = EINA_FALSE; const char *found; char *utf8; const Evas_Object *tb = elm_entry_textblock_get(entry); Evas_Textblock_Cursor *end, *start, *mcur; size_t initial_pos; if (!text || !*text) return EINA_FALSE; mcur = (Evas_Textblock_Cursor *) evas_object_textblock_cursor_get(tb); if (!cur_find) { cur_find = evas_object_textblock_cursor_new(tb); } else if (!evas_textblock_cursor_compare(cur_find, mcur)) { try_next = EINA_TRUE; } if (forward) { evas_textblock_cursor_paragraph_last(cur_find); start = mcur; end = cur_find; } else { /* Not correct, more adjustments needed. */ evas_textblock_cursor_paragraph_first(cur_find); start = cur_find; end = mcur; } initial_pos = evas_textblock_cursor_pos_get(start); utf8 = evas_textblock_cursor_range_text_get(start, end, EVAS_TEXTBLOCK_TEXT_PLAIN); if (!utf8) return EINA_FALSE; if (try_next && jump_next) { found = strstr(utf8 + 1, text); if (!found) { found = utf8; } } else { found = strstr(utf8, text); } if (found) { size_t pos = 0; int idx = 0; while ((utf8 + idx) < found) { pos++; eina_unicode_utf8_get_next(utf8, &idx); } elm_entry_select_none(entry); evas_textblock_cursor_pos_set(mcur, pos + initial_pos + strlen(text)); elm_entry_cursor_selection_begin(entry); elm_entry_cursor_pos_set(entry, pos + initial_pos); elm_entry_cursor_selection_end(entry); evas_textblock_cursor_copy(mcur, cur_find); } free(utf8); return !!found; }
EINA_DEPRECATED EAPI void elm_scrolled_entry_select_none(Evas_Object *obj) {elm_entry_select_none(obj);}