Hello all,

If there are tags (<b>abc def</b>) in elm_entry,
elm_entry_cursor_content_get() returns the wrong character.
It seems to be off by the length of the starting tag and may be short
due to the closing tag.

Please see the attached source for demonstration of the problem.


brian

-- 
brian
------------------

Cool-Karaoke - The smallest recording studio, in your palm, open-sourced
http://cool-idea.com.tw/

iMaGiNaTiOn iS mOrE iMpOrTaNt tHaN kNoWlEdGe
#include <Elementary.h>

static int is_delimiter(char ch)
{
        if ((unsigned char)ch >= 0x80)
                return 1;

        if (!isalpha(ch) && !isdigit(ch) && (ch != '\'') && (ch != '-'))
        //if (!isalpha(ch) && !isdigit(ch) && (ch != '\''))
                return 1;
        else
                return 0;
}

static char *_entry_cursor_word(Evas_Object *obj)
{
        const char *content;
        char buf[256];
        int idx = 0;

        //
        // Go to the beginning of the word
        //
        while ((content = elm_entry_cursor_content_get(obj))) {
                if (elm_entry_cursor_is_format_get(obj)) {
                        if (idx > 0) {
                                idx--;
                                elm_entry_cursor_next(obj);
                        }
                        break;
                }

                //printf("%d. %s\n", idx, content);
                if (is_delimiter(content[0])) {
                        elm_entry_cursor_next(obj);
                        break;
                }
                if (!elm_entry_cursor_prev(obj)) {
                        break;
                }
                idx++;
        }

        buf[0] = 0;
        while (!elm_entry_cursor_is_format_get(obj) && (content = 
elm_entry_cursor_content_get(obj))) {
                //printf("%d. %s\n", idx, content);
                if (is_delimiter(content[0])) {
                        break;
                }
                strcat(buf, content);
                if (!elm_entry_cursor_next(obj)) {
                        break;
                }
        }
        //printf("%s : idx=%d buf='%s'\n", __func__, idx, buf);

        //printf("%s : clicked on '%s' -> '%s'\n", __FUNCTION__, buf, 
elm_entry_markup_to_utf8(buf));
    elm_entry_select_none(obj);

        if (!buf[0])
                return NULL;
        else {
                int len;
                char *p;

                //
                // Check if there are multiple hyphens...
                //
                p = strchr(buf, '-');
                if (p) {
                        char *q = strchr(p+1, '-');
                        if (q) {
                                // got you!
                                if (idx >= (p - buf)) {
                                        /* latter part */
                                        char buf2[256];

                                        q = strrchr(buf, '-');

                                        strcpy(buf2, q+1);
                                        strcpy(buf, buf2);
                                } else {
                                        /* front part */
                                        *p = 0;
                                }
                        }
                }


                //
                // Check if it's a simple plural form
                //

                len = strlen(buf);
                if (len >= 2 && !strncmp(buf + len - 2, "'s", 2))
                        buf[len-2] = 0;
                printf("  -> word='%s'\n", buf);
                return strdup(buf);
        }
        //return elm_entry_markup_to_utf8(buf);
}

static void _entry_retrieve_clicked_word(Evas_Object *obj)
{
        const char *content;

        while ((content = elm_entry_cursor_content_get(obj))) {
                if (!content[0])
                        break;
                printf("Content: '%s'\n", content);
                if (!elm_entry_cursor_next(obj))
                        break;
        }
}

static void _entry_clicked(void *data, Evas_Object *obj, void *event_info)
{
#if 0
        char *word;

        printf("%s in\n", __FUNCTION__);

        //_entry_retrieve_clicked_word(obj);
        word = _entry_cursor_word(obj);
        printf(" word: '%s'\n", word);
#else
        const char *clicked;

        clicked = elm_entry_cursor_content_get(obj);
        printf("Clicked: '%s'\n", clicked);
#endif
}

/* if someone presses the close button on our window - exit nicely */
static void
win_del(void *data, Evas_Object *obj, void *event_info)
{
   /* cleanly exit */
   elm_exit();
}

EAPI int
elm_main(int argc, char **argv)
{
   Evas_Object *win, *bg, *bx, *en;

   win = elm_win_add(NULL, "dialog", ELM_WIN_BASIC);
   evas_object_smart_callback_add(win, "delete-request", win_del, NULL);

   bg = elm_bg_add(win);
   evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   elm_win_resize_object_add(win, bg);
   evas_object_show(bg);

   bx = elm_box_add(win);
   evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   evas_object_size_hint_align_set(bx, EVAS_HINT_FILL, EVAS_HINT_FILL);
   elm_win_resize_object_add(win, bx);
   evas_object_show(bx);

   en = elm_entry_add(win);
   elm_entry_line_wrap_set(en, 1);
   elm_entry_line_char_wrap_set(en, 1);
   elm_entry_editable_set(en, 0);
   elm_object_scale_set(en, 1.6);
#if 0
   /* Chinese + English */
   elm_entry_entry_set(en, "中英混合 english mixed with chinese");
#else
   elm_entry_entry_set(en, "<b>english mixed with chinese</b>");
#endif
   evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   evas_object_size_hint_align_set(en, EVAS_HINT_FILL, EVAS_HINT_FILL);
   elm_box_pack_end(bx, en);
   evas_object_show(en);
   elm_entry_editable_set(en, 0);

   evas_object_smart_callback_add(en, "clicked", _entry_clicked, NULL);

   /* show the window */
   evas_object_show(win);
   evas_object_resize(win, 320, 240);

   /* get going and draw/respond to the user */
   elm_run();
   /* standard shutdown */
   elm_shutdown();
   /* return/exit code of app signals ok/cancel (0 == ok), (-1 == cancel) */
   return 0;
}
ELM_MAIN()
------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:

Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to