Пример #1
0
PyObject *
Evas_Textblock_Cursor_PyObject__pos_get(Evas_Textblock_Cursor_PyObject *self, PyObject * args)
{
    int pos;
    BENCH_START
    pos = evas_textblock_cursor_pos_get(self->cursor);
    BENCH_END
    return Py_BuildValue("i", pos);
}
Пример #2
0
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;
}